<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<title>API: autocomplete   AutoComplete.js  (YUI Library)</title>
	<link rel="stylesheet" type="text/css" href="assets/api.css">
</head>

<body id="yahoo-com">
<div id="doc3" class="yui-t2">

	<div id="hd">
        <h1>Yahoo! UI Library</h1>
        <h3>AutoComplete Widget&nbsp; <span class="subtitle">2.2.2</span></h3>
        <p>
        <a href="./index.html">Yahoo! UI Library</a> 
            &gt; <a href="./module_autocomplete.html">autocomplete</a>
                
                 &gt; AutoComplete.js (source view) 
            </p>
	</div>

	<div id="bd">
		<div id="yui-main">
			<div class="yui-b">

                    <div id="srcout">
<div class="highlight" ><pre> <span class="c">/**</span>
<span class="c"> * The AutoComplete control provides the front-end logic for text-entry suggestion and</span>
<span class="c"> * completion functionality.</span>
<span class="c"> *</span>
<span class="c"> * @module autocomplete</span>
<span class="c"> * @requires yahoo, dom, event, datasource</span>
<span class="c"> * @optional animation, connection</span>
<span class="c"> * @namespace YAHOO.widget</span>
<span class="c"> * @title AutoComplete Widget</span>
<span class="c"> */</span>

<span class="c">/****************************************************************************/</span>
<span class="c">/****************************************************************************/</span>
<span class="c">/****************************************************************************/</span>

<span class="c">/**</span>
<span class="c"> * The AutoComplete class provides the customizable functionality of a plug-and-play DHTML</span>
<span class="c"> * auto completion widget.  Some key features:</span>
<span class="c"> * &lt;ul&gt;</span>
<span class="c"> * &lt;li&gt;Navigate with up/down arrow keys and/or mouse to pick a selection&lt;/li&gt;</span>
<span class="c"> * &lt;li&gt;The drop down container can &quot;roll down&quot; or &quot;fly out&quot; via configurable</span>
<span class="c"> * animation&lt;/li&gt;</span>
<span class="c"> * &lt;li&gt;UI look-and-feel customizable through CSS, including container</span>
<span class="c"> * attributes, borders, position, fonts, etc&lt;/li&gt;</span>
<span class="c"> * &lt;/ul&gt;</span>
<span class="c"> *</span>
<span class="c"> * @class AutoComplete</span>
<span class="c"> * @constructor</span>
<span class="c"> * @param elInput {HTMLElement} DOM element reference of an input field.</span>
<span class="c"> * @param elInput {String} String ID of an input field.</span>
<span class="c"> * @param elContainer {HTMLElement} DOM element reference of an existing DIV.</span>
<span class="c"> * @param elContainer {String} String ID of an existing DIV.</span>
<span class="c"> * @param oDataSource {YAHOO.widget.DataSource} DataSource instance.</span>
<span class="c"> * @param oConfigs {Object} (optional) Object literal of configuration params.</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">elInput</span><span class="o">,</span><span class="nx">elContainer</span><span class="o">,</span><span class="nx">oDataSource</span><span class="o">,</span><span class="nx">oConfigs</span><span class="o">)</span> <span class="o">{</span>
    <span class="k">if</span><span class="o">(</span><span class="nx">elInput</span> <span class="o">&amp;&amp;</span> <span class="nx">elContainer</span> <span class="o">&amp;&amp;</span> <span class="nx">oDataSource</span><span class="o">)</span> <span class="o">{</span>
        <span class="c">// Validate DataSource</span>
<span class="c"></span>        <span class="k">if</span><span class="o">(</span><span class="nx">oDataSource</span> <span class="k">instanceof</span> <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">DataSource</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">dataSource</span> <span class="o">=</span> <span class="nx">oDataSource</span><span class="o">;</span>
        <span class="o">}</span>
        <span class="k">else</span> <span class="o">{</span>
            <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s2">&quot;Could not instantiate AutoComplete due to an invalid DataSource&quot;</span><span class="o">,</span> <span class="s2">&quot;error&quot;</span><span class="o">,</span> <span class="k">this</span><span class="o">.</span><span class="nx">toString</span><span class="o">());</span>
            <span class="k">return</span><span class="o">;</span>
        <span class="o">}</span>

        <span class="c">// Validate input element</span>
<span class="c"></span>        <span class="k">if</span><span class="o">(</span><span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">Dom</span><span class="o">.</span><span class="nx">inDocument</span><span class="o">(</span><span class="nx">elInput</span><span class="o">))</span> <span class="o">{</span>
            <span class="k">if</span><span class="o">(</span><span class="nx">YAHOO</span><span class="o">.</span><span class="nx">lang</span><span class="o">.</span><span class="nx">isString</span><span class="o">(</span><span class="nx">elInput</span><span class="o">))</span> <span class="o">{</span>
                    <span class="k">this</span><span class="o">.</span><span class="nx">_sName</span> <span class="o">=</span> <span class="s2">&quot;instance&quot;</span> <span class="o">+</span> <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">_nIndex</span> <span class="o">+</span> <span class="s2">&quot; &quot;</span> <span class="o">+</span> <span class="nx">elInput</span><span class="o">;</span>
                    <span class="k">this</span><span class="o">.</span><span class="nx">_oTextbox</span> <span class="o">=</span> <span class="nb">document</span><span class="o">.</span><span class="nx">getElementById</span><span class="o">(</span><span class="nx">elInput</span><span class="o">);</span>
            <span class="o">}</span>
            <span class="k">else</span> <span class="o">{</span>
                <span class="k">this</span><span class="o">.</span><span class="nx">_sName</span> <span class="o">=</span> <span class="o">(</span><span class="nx">elInput</span><span class="o">.</span><span class="nx">id</span><span class="o">)</span> <span class="o">?</span>
                    <span class="s2">&quot;instance&quot;</span> <span class="o">+</span> <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">_nIndex</span> <span class="o">+</span> <span class="s2">&quot; &quot;</span> <span class="o">+</span> <span class="nx">elInput</span><span class="o">.</span><span class="nx">id</span><span class="o">:</span>
                    <span class="s2">&quot;instance&quot;</span> <span class="o">+</span> <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">_nIndex</span><span class="o">;</span>
                <span class="k">this</span><span class="o">.</span><span class="nx">_oTextbox</span> <span class="o">=</span> <span class="nx">elInput</span><span class="o">;</span>
            <span class="o">}</span>
        <span class="o">}</span>
        <span class="k">else</span> <span class="o">{</span>
            <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s2">&quot;Could not instantiate AutoComplete due to an invalid input element&quot;</span><span class="o">,</span> <span class="s2">&quot;error&quot;</span><span class="o">,</span> <span class="k">this</span><span class="o">.</span><span class="nx">toString</span><span class="o">());</span>
            <span class="k">return</span><span class="o">;</span>
        <span class="o">}</span>

        <span class="c">// Validate container element</span>
<span class="c"></span>        <span class="k">if</span><span class="o">(</span><span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">Dom</span><span class="o">.</span><span class="nx">inDocument</span><span class="o">(</span><span class="nx">elContainer</span><span class="o">))</span> <span class="o">{</span>
            <span class="k">if</span><span class="o">(</span><span class="nx">YAHOO</span><span class="o">.</span><span class="nx">lang</span><span class="o">.</span><span class="nx">isString</span><span class="o">(</span><span class="nx">elContainer</span><span class="o">))</span> <span class="o">{</span>
                    <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span> <span class="o">=</span> <span class="nb">document</span><span class="o">.</span><span class="nx">getElementById</span><span class="o">(</span><span class="nx">elContainer</span><span class="o">);</span>
            <span class="o">}</span>
            <span class="k">else</span> <span class="o">{</span>
                <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span> <span class="o">=</span> <span class="nx">elContainer</span><span class="o">;</span>
            <span class="o">}</span>
            <span class="k">if</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">style</span><span class="o">.</span><span class="nx">display</span> <span class="o">==</span> <span class="s2">&quot;none&quot;</span><span class="o">)</span> <span class="o">{</span>
                <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s2">&quot;The container may not display properly if display is set to \&quot;none\&quot; in CSS&quot;</span><span class="o">,</span> <span class="s2">&quot;warn&quot;</span><span class="o">,</span> <span class="k">this</span><span class="o">.</span><span class="nx">toString</span><span class="o">());</span>
            <span class="o">}</span>
        <span class="o">}</span>
        <span class="k">else</span> <span class="o">{</span>
            <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s2">&quot;Could not instantiate AutoComplete due to an invalid container element&quot;</span><span class="o">,</span> <span class="s2">&quot;error&quot;</span><span class="o">,</span> <span class="k">this</span><span class="o">.</span><span class="nx">toString</span><span class="o">());</span>
            <span class="k">return</span><span class="o">;</span>
        <span class="o">}</span>

        <span class="c">// Set any config params passed in to override defaults</span>
<span class="c"></span>        <span class="k">if</span><span class="o">(</span><span class="nx">oConfigs</span> <span class="o">&amp;&amp;</span> <span class="o">(</span><span class="nx">oConfigs</span><span class="o">.</span><span class="nx">constructor</span> <span class="o">==</span> <span class="nb">Object</span><span class="o">))</span> <span class="o">{</span>
            <span class="k">for</span><span class="o">(</span><span class="k">var</span> <span class="nx">sConfig</span> <span class="k">in</span> <span class="nx">oConfigs</span><span class="o">)</span> <span class="o">{</span>
                <span class="k">if</span><span class="o">(</span><span class="nx">sConfig</span><span class="o">)</span> <span class="o">{</span>
                    <span class="k">this</span><span class="o">[</span><span class="nx">sConfig</span><span class="o">]</span> <span class="o">=</span> <span class="nx">oConfigs</span><span class="o">[</span><span class="nx">sConfig</span><span class="o">];</span>
                <span class="o">}</span>
            <span class="o">}</span>
        <span class="o">}</span>

        <span class="c">// Initialization sequence</span>
<span class="c"></span>        <span class="k">this</span><span class="o">.</span><span class="nx">_initContainer</span><span class="o">();</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">_initProps</span><span class="o">();</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">_initList</span><span class="o">();</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">_initContainerHelpers</span><span class="o">();</span>

        <span class="c">// Set up events</span>
<span class="c"></span>        <span class="k">var</span> <span class="nx">oSelf</span> <span class="o">=</span> <span class="k">this</span><span class="o">;</span>
        <span class="k">var</span> <span class="nx">oTextbox</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_oTextbox</span><span class="o">;</span>
        <span class="c">// Events are actually for the content module within the container</span>
<span class="c"></span>        <span class="k">var</span> <span class="nx">oContent</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">;</span>

        <span class="c">// Dom events</span>
<span class="c"></span>        <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">Event</span><span class="o">.</span><span class="nx">addListener</span><span class="o">(</span><span class="nx">oTextbox</span><span class="o">,</span><span class="s2">&quot;keyup&quot;</span><span class="o">,</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_onTextboxKeyUp</span><span class="o">,</span><span class="nx">oSelf</span><span class="o">);</span>
        <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">Event</span><span class="o">.</span><span class="nx">addListener</span><span class="o">(</span><span class="nx">oTextbox</span><span class="o">,</span><span class="s2">&quot;keydown&quot;</span><span class="o">,</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_onTextboxKeyDown</span><span class="o">,</span><span class="nx">oSelf</span><span class="o">);</span>
        <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">Event</span><span class="o">.</span><span class="nx">addListener</span><span class="o">(</span><span class="nx">oTextbox</span><span class="o">,</span><span class="s2">&quot;focus&quot;</span><span class="o">,</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_onTextboxFocus</span><span class="o">,</span><span class="nx">oSelf</span><span class="o">);</span>
        <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">Event</span><span class="o">.</span><span class="nx">addListener</span><span class="o">(</span><span class="nx">oTextbox</span><span class="o">,</span><span class="s2">&quot;blur&quot;</span><span class="o">,</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_onTextboxBlur</span><span class="o">,</span><span class="nx">oSelf</span><span class="o">);</span>
        <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">Event</span><span class="o">.</span><span class="nx">addListener</span><span class="o">(</span><span class="nx">oContent</span><span class="o">,</span><span class="s2">&quot;mouseover&quot;</span><span class="o">,</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_onContainerMouseover</span><span class="o">,</span><span class="nx">oSelf</span><span class="o">);</span>
        <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">Event</span><span class="o">.</span><span class="nx">addListener</span><span class="o">(</span><span class="nx">oContent</span><span class="o">,</span><span class="s2">&quot;mouseout&quot;</span><span class="o">,</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_onContainerMouseout</span><span class="o">,</span><span class="nx">oSelf</span><span class="o">);</span>
        <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">Event</span><span class="o">.</span><span class="nx">addListener</span><span class="o">(</span><span class="nx">oContent</span><span class="o">,</span><span class="s2">&quot;scroll&quot;</span><span class="o">,</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_onContainerScroll</span><span class="o">,</span><span class="nx">oSelf</span><span class="o">);</span>
        <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">Event</span><span class="o">.</span><span class="nx">addListener</span><span class="o">(</span><span class="nx">oContent</span><span class="o">,</span><span class="s2">&quot;resize&quot;</span><span class="o">,</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_onContainerResize</span><span class="o">,</span><span class="nx">oSelf</span><span class="o">);</span>
        <span class="k">if</span><span class="o">(</span><span class="nx">oTextbox</span><span class="o">.</span><span class="nx">form</span><span class="o">)</span> <span class="o">{</span>
            <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">Event</span><span class="o">.</span><span class="nx">addListener</span><span class="o">(</span><span class="nx">oTextbox</span><span class="o">.</span><span class="nx">form</span><span class="o">,</span><span class="s2">&quot;submit&quot;</span><span class="o">,</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_onFormSubmit</span><span class="o">,</span><span class="nx">oSelf</span><span class="o">);</span>
        <span class="o">}</span>
        <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">Event</span><span class="o">.</span><span class="nx">addListener</span><span class="o">(</span><span class="nx">oTextbox</span><span class="o">,</span><span class="s2">&quot;keypress&quot;</span><span class="o">,</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_onTextboxKeyPress</span><span class="o">,</span><span class="nx">oSelf</span><span class="o">);</span>

        <span class="c">// Custom events</span>
<span class="c"></span>        <span class="k">this</span><span class="o">.</span><span class="nx">textboxFocusEvent</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">CustomEvent</span><span class="o">(</span><span class="s2">&quot;textboxFocus&quot;</span><span class="o">,</span> <span class="k">this</span><span class="o">);</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">textboxKeyEvent</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">CustomEvent</span><span class="o">(</span><span class="s2">&quot;textboxKey&quot;</span><span class="o">,</span> <span class="k">this</span><span class="o">);</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">dataRequestEvent</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">CustomEvent</span><span class="o">(</span><span class="s2">&quot;dataRequest&quot;</span><span class="o">,</span> <span class="k">this</span><span class="o">);</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">dataReturnEvent</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">CustomEvent</span><span class="o">(</span><span class="s2">&quot;dataReturn&quot;</span><span class="o">,</span> <span class="k">this</span><span class="o">);</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">dataErrorEvent</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">CustomEvent</span><span class="o">(</span><span class="s2">&quot;dataError&quot;</span><span class="o">,</span> <span class="k">this</span><span class="o">);</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">containerExpandEvent</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">CustomEvent</span><span class="o">(</span><span class="s2">&quot;containerExpand&quot;</span><span class="o">,</span> <span class="k">this</span><span class="o">);</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">typeAheadEvent</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">CustomEvent</span><span class="o">(</span><span class="s2">&quot;typeAhead&quot;</span><span class="o">,</span> <span class="k">this</span><span class="o">);</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">itemMouseOverEvent</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">CustomEvent</span><span class="o">(</span><span class="s2">&quot;itemMouseOver&quot;</span><span class="o">,</span> <span class="k">this</span><span class="o">);</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">itemMouseOutEvent</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">CustomEvent</span><span class="o">(</span><span class="s2">&quot;itemMouseOut&quot;</span><span class="o">,</span> <span class="k">this</span><span class="o">);</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">itemArrowToEvent</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">CustomEvent</span><span class="o">(</span><span class="s2">&quot;itemArrowTo&quot;</span><span class="o">,</span> <span class="k">this</span><span class="o">);</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">itemArrowFromEvent</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">CustomEvent</span><span class="o">(</span><span class="s2">&quot;itemArrowFrom&quot;</span><span class="o">,</span> <span class="k">this</span><span class="o">);</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">itemSelectEvent</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">CustomEvent</span><span class="o">(</span><span class="s2">&quot;itemSelect&quot;</span><span class="o">,</span> <span class="k">this</span><span class="o">);</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">unmatchedItemSelectEvent</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">CustomEvent</span><span class="o">(</span><span class="s2">&quot;unmatchedItemSelect&quot;</span><span class="o">,</span> <span class="k">this</span><span class="o">);</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">selectionEnforceEvent</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">CustomEvent</span><span class="o">(</span><span class="s2">&quot;selectionEnforce&quot;</span><span class="o">,</span> <span class="k">this</span><span class="o">);</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">containerCollapseEvent</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">CustomEvent</span><span class="o">(</span><span class="s2">&quot;containerCollapse&quot;</span><span class="o">,</span> <span class="k">this</span><span class="o">);</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">textboxBlurEvent</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">CustomEvent</span><span class="o">(</span><span class="s2">&quot;textboxBlur&quot;</span><span class="o">,</span> <span class="k">this</span><span class="o">);</span>
        
        <span class="c">// Finish up</span>
<span class="c"></span>        <span class="nx">oTextbox</span><span class="o">.</span><span class="nx">setAttribute</span><span class="o">(</span><span class="s2">&quot;autocomplete&quot;</span><span class="o">,</span><span class="s2">&quot;off&quot;</span><span class="o">);</span>
        <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">_nIndex</span><span class="o">++;</span>
        <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s2">&quot;AutoComplete initialized&quot;</span><span class="o">,</span><span class="s2">&quot;info&quot;</span><span class="o">,</span><span class="k">this</span><span class="o">.</span><span class="nx">toString</span><span class="o">());</span>
    <span class="o">}</span>
    <span class="c">// Required arguments were not found</span>
<span class="c"></span>    <span class="k">else</span> <span class="o">{</span>
        <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s2">&quot;Could not instantiate AutoComplete due invalid arguments&quot;</span><span class="o">,</span> <span class="s2">&quot;error&quot;</span><span class="o">,</span> <span class="k">this</span><span class="o">.</span><span class="nx">toString</span><span class="o">());</span>
    <span class="o">}</span>
<span class="o">};</span>

<span class="c">/////////////////////////////////////////////////////////////////////////////</span>
<span class="c">//</span>
<span class="c">// Public member variables</span>
<span class="c">//</span>
<span class="c">/////////////////////////////////////////////////////////////////////////////</span>
<span class="c"></span>
<span class="c">/**</span>
<span class="c"> * The DataSource object that encapsulates the data used for auto completion.</span>
<span class="c"> * This object should be an inherited object from YAHOO.widget.DataSource.</span>
<span class="c"> *</span>
<span class="c"> * @property dataSource</span>
<span class="c"> * @type YAHOO.widget.DataSource</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">dataSource</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Number of characters that must be entered before querying for results. A negative value</span>
<span class="c"> * effectively turns off the widget. A value of 0 allows queries of null or empty string</span>
<span class="c"> * values.</span>
<span class="c"> *</span>
<span class="c"> * @property minQueryLength</span>
<span class="c"> * @type Number</span>
<span class="c"> * @default 1</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">minQueryLength</span> <span class="o">=</span> <span class="m">1</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Maximum number of results to display in results container.</span>
<span class="c"> *</span>
<span class="c"> * @property maxResultsDisplayed</span>
<span class="c"> * @type Number</span>
<span class="c"> * @default 10</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">maxResultsDisplayed</span> <span class="o">=</span> <span class="m">10</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Number of seconds to delay before submitting a query request.  If a query</span>
<span class="c"> * request is received before a previous one has completed its delay, the</span>
<span class="c"> * previous request is cancelled and the new request is set to the delay.</span>
<span class="c"> *</span>
<span class="c"> * @property queryDelay</span>
<span class="c"> * @type Number</span>
<span class="c"> * @default 0.5</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">queryDelay</span> <span class="o">=</span> <span class="m">0</span><span class="o">.</span><span class="m">5</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Class name of a highlighted item within results container.</span>
<span class="c"> *</span>
<span class="c"> * @property highlightClassName</span>
<span class="c"> * @type String</span>
<span class="c"> * @default &quot;yui-ac-highlight&quot;</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">highlightClassName</span> <span class="o">=</span> <span class="s2">&quot;yui-ac-highlight&quot;</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Class name of a pre-highlighted item within results container.</span>
<span class="c"> *</span>
<span class="c"> * @property prehighlightClassName</span>
<span class="c"> * @type String</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">prehighlightClassName</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Query delimiter. A single character separator for multiple delimited</span>
<span class="c"> * selections. Multiple delimiter characteres may be defined as an array of</span>
<span class="c"> * strings. A null value or empty string indicates that query results cannot</span>
<span class="c"> * be delimited. This feature is not recommended if you need forceSelection to</span>
<span class="c"> * be true.</span>
<span class="c"> *</span>
<span class="c"> * @property delimChar</span>
<span class="c"> * @type String | String[]</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">delimChar</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Whether or not the first item in results container should be automatically highlighted</span>
<span class="c"> * on expand.</span>
<span class="c"> *</span>
<span class="c"> * @property autoHighlight</span>
<span class="c"> * @type Boolean</span>
<span class="c"> * @default true</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">autoHighlight</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Whether or not the input field should be automatically updated</span>
<span class="c"> * with the first query result as the user types, auto-selecting the substring</span>
<span class="c"> * that the user has not typed.</span>
<span class="c"> *</span>
<span class="c"> * @property typeAhead</span>
<span class="c"> * @type Boolean</span>
<span class="c"> * @default false</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">typeAhead</span> <span class="o">=</span> <span class="kc">false</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Whether or not to animate the expansion/collapse of the results container in the</span>
<span class="c"> * horizontal direction.</span>
<span class="c"> *</span>
<span class="c"> * @property animHoriz</span>
<span class="c"> * @type Boolean</span>
<span class="c"> * @default false</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">animHoriz</span> <span class="o">=</span> <span class="kc">false</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Whether or not to animate the expansion/collapse of the results container in the</span>
<span class="c"> * vertical direction.</span>
<span class="c"> *</span>
<span class="c"> * @property animVert</span>
<span class="c"> * @type Boolean</span>
<span class="c"> * @default true</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">animVert</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Speed of container expand/collapse animation, in seconds..</span>
<span class="c"> *</span>
<span class="c"> * @property animSpeed</span>
<span class="c"> * @type Number</span>
<span class="c"> * @default 0.3</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">animSpeed</span> <span class="o">=</span> <span class="m">0</span><span class="o">.</span><span class="m">3</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Whether or not to force the user&#39;s selection to match one of the query</span>
<span class="c"> * results. Enabling this feature essentially transforms the input field into a</span>
<span class="c"> * &amp;lt;select&amp;gt; field. This feature is not recommended with delimiter character(s)</span>
<span class="c"> * defined.</span>
<span class="c"> *</span>
<span class="c"> * @property forceSelection</span>
<span class="c"> * @type Boolean</span>
<span class="c"> * @default false</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">forceSelection</span> <span class="o">=</span> <span class="kc">false</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Whether or not to allow browsers to cache user-typed input in the input</span>
<span class="c"> * field. Disabling this feature will prevent the widget from setting the</span>
<span class="c"> * autocomplete=&quot;off&quot; on the input field. When autocomplete=&quot;off&quot;</span>
<span class="c"> * and users click the back button after form submission, user-typed input can</span>
<span class="c"> * be prefilled by the browser from its cache. This caching of user input may</span>
<span class="c"> * not be desired for sensitive data, such as credit card numbers, in which</span>
<span class="c"> * case, implementers should consider setting allowBrowserAutocomplete to false.</span>
<span class="c"> *</span>
<span class="c"> * @property allowBrowserAutocomplete</span>
<span class="c"> * @type Boolean</span>
<span class="c"> * @default true</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">allowBrowserAutocomplete</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Whether or not the results container should always be displayed.</span>
<span class="c"> * Enabling this feature displays the container when the widget is instantiated</span>
<span class="c"> * and prevents the toggling of the container to a collapsed state.</span>
<span class="c"> *</span>
<span class="c"> * @property alwaysShowContainer</span>
<span class="c"> * @type Boolean</span>
<span class="c"> * @default false</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">alwaysShowContainer</span> <span class="o">=</span> <span class="kc">false</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Whether or not to use an iFrame to layer over Windows form elements in</span>
<span class="c"> * IE. Set to true only when the results container will be on top of a</span>
<span class="c"> * &amp;lt;select&amp;gt; field in IE and thus exposed to the IE z-index bug (i.e.,</span>
<span class="c"> * 5.5 &lt; IE &lt; 7).</span>
<span class="c"> *</span>
<span class="c"> * @property useIFrame</span>
<span class="c"> * @type Boolean</span>
<span class="c"> * @default false</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">useIFrame</span> <span class="o">=</span> <span class="kc">false</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Whether or not the results container should have a shadow.</span>
<span class="c"> *</span>
<span class="c"> * @property useShadow</span>
<span class="c"> * @type Boolean</span>
<span class="c"> * @default false</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">useShadow</span> <span class="o">=</span> <span class="kc">false</span><span class="o">;</span>

<span class="c">/////////////////////////////////////////////////////////////////////////////</span>
<span class="c">//</span>
<span class="c">// Public methods</span>
<span class="c">//</span>
<span class="c">/////////////////////////////////////////////////////////////////////////////</span>
<span class="c"></span>
 <span class="c">/**</span>
<span class="c"> * Public accessor to the unique name of the AutoComplete instance.</span>
<span class="c"> *</span>
<span class="c"> * @method toString</span>
<span class="c"> * @return {String} Unique name of the AutoComplete instance.</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">toString</span> <span class="o">=</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
    <span class="k">return</span> <span class="s2">&quot;AutoComplete &quot;</span> <span class="o">+</span> <span class="k">this</span><span class="o">.</span><span class="nx">_sName</span><span class="o">;</span>
<span class="o">};</span>

 <span class="c">/**</span>
<span class="c"> * Returns true if container is in an expanded state, false otherwise.</span>
<span class="c"> *</span>
<span class="c"> * @method isContainerOpen</span>
<span class="c"> * @return {Boolean} Returns true if container is in an expanded state, false otherwise.</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">isContainerOpen</span> <span class="o">=</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
    <span class="k">return</span> <span class="k">this</span><span class="o">.</span><span class="nx">_bContainerOpen</span><span class="o">;</span>
<span class="o">};</span>

<span class="c">/**</span>
<span class="c"> * Public accessor to the internal array of DOM &amp;lt;li&amp;gt; elements that</span>
<span class="c"> * display query results within the results container.</span>
<span class="c"> *</span>
<span class="c"> * @method getListItems</span>
<span class="c"> * @return {HTMLElement[]} Array of &amp;lt;li&amp;gt; elements within the results container.</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">getListItems</span> <span class="o">=</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
    <span class="k">return</span> <span class="k">this</span><span class="o">.</span><span class="nx">_aListItems</span><span class="o">;</span>
<span class="o">};</span>

<span class="c">/**</span>
<span class="c"> * Public accessor to the data held in an &amp;lt;li&amp;gt; element of the</span>
<span class="c"> * results container.</span>
<span class="c"> *</span>
<span class="c"> * @method getListItemData</span>
<span class="c"> * @return {Object | Object[]} Object or array of result data or null</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">getListItemData</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">oListItem</span><span class="o">)</span> <span class="o">{</span>
    <span class="k">if</span><span class="o">(</span><span class="nx">oListItem</span><span class="o">.</span><span class="nx">_oResultData</span><span class="o">)</span> <span class="o">{</span>
        <span class="k">return</span> <span class="nx">oListItem</span><span class="o">.</span><span class="nx">_oResultData</span><span class="o">;</span>
    <span class="o">}</span>
    <span class="k">else</span> <span class="o">{</span>
        <span class="k">return</span> <span class="kc">false</span><span class="o">;</span>
    <span class="o">}</span>
<span class="o">};</span>

<span class="c">/**</span>
<span class="c"> * Sets HTML markup for the results container header. This markup will be</span>
<span class="c"> * inserted within a &amp;lt;div&amp;gt; tag with a class of &quot;yui-ac-hd&quot;.</span>
<span class="c"> *</span>
<span class="c"> * @method setHeader</span>
<span class="c"> * @param sHeader {String} HTML markup for results container header.</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">setHeader</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">sHeader</span><span class="o">)</span> <span class="o">{</span>
    <span class="k">if</span><span class="o">(</span><span class="nx">sHeader</span><span class="o">)</span> <span class="o">{</span>
        <span class="k">if</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">.</span><span class="nx">_oHeader</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">.</span><span class="nx">_oHeader</span><span class="o">.</span><span class="nx">innerHTML</span> <span class="o">=</span> <span class="nx">sHeader</span><span class="o">;</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">.</span><span class="nx">_oHeader</span><span class="o">.</span><span class="nx">style</span><span class="o">.</span><span class="nx">display</span> <span class="o">=</span> <span class="s2">&quot;block&quot;</span><span class="o">;</span>
        <span class="o">}</span>
    <span class="o">}</span>
    <span class="k">else</span> <span class="o">{</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">.</span><span class="nx">_oHeader</span><span class="o">.</span><span class="nx">innerHTML</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span><span class="o">;</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">.</span><span class="nx">_oHeader</span><span class="o">.</span><span class="nx">style</span><span class="o">.</span><span class="nx">display</span> <span class="o">=</span> <span class="s2">&quot;none&quot;</span><span class="o">;</span>
    <span class="o">}</span>
<span class="o">};</span>

<span class="c">/**</span>
<span class="c"> * Sets HTML markup for the results container footer. This markup will be</span>
<span class="c"> * inserted within a &amp;lt;div&amp;gt; tag with a class of &quot;yui-ac-ft&quot;.</span>
<span class="c"> *</span>
<span class="c"> * @method setFooter</span>
<span class="c"> * @param sFooter {String} HTML markup for results container footer.</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">setFooter</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">sFooter</span><span class="o">)</span> <span class="o">{</span>
    <span class="k">if</span><span class="o">(</span><span class="nx">sFooter</span><span class="o">)</span> <span class="o">{</span>
        <span class="k">if</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">.</span><span class="nx">_oFooter</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">.</span><span class="nx">_oFooter</span><span class="o">.</span><span class="nx">innerHTML</span> <span class="o">=</span> <span class="nx">sFooter</span><span class="o">;</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">.</span><span class="nx">_oFooter</span><span class="o">.</span><span class="nx">style</span><span class="o">.</span><span class="nx">display</span> <span class="o">=</span> <span class="s2">&quot;block&quot;</span><span class="o">;</span>
        <span class="o">}</span>
    <span class="o">}</span>
    <span class="k">else</span> <span class="o">{</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">.</span><span class="nx">_oFooter</span><span class="o">.</span><span class="nx">innerHTML</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span><span class="o">;</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">.</span><span class="nx">_oFooter</span><span class="o">.</span><span class="nx">style</span><span class="o">.</span><span class="nx">display</span> <span class="o">=</span> <span class="s2">&quot;none&quot;</span><span class="o">;</span>
    <span class="o">}</span>
<span class="o">};</span>

<span class="c">/**</span>
<span class="c"> * Sets HTML markup for the results container body. This markup will be</span>
<span class="c"> * inserted within a &amp;lt;div&amp;gt; tag with a class of &quot;yui-ac-bd&quot;.</span>
<span class="c"> *</span>
<span class="c"> * @method setBody</span>
<span class="c"> * @param sBody {String} HTML markup for results container body.</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">setBody</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">sBody</span><span class="o">)</span> <span class="o">{</span>
    <span class="k">if</span><span class="o">(</span><span class="nx">sBody</span><span class="o">)</span> <span class="o">{</span>
        <span class="k">if</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">.</span><span class="nx">_oBody</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">.</span><span class="nx">_oBody</span><span class="o">.</span><span class="nx">innerHTML</span> <span class="o">=</span> <span class="nx">sBody</span><span class="o">;</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">.</span><span class="nx">_oBody</span><span class="o">.</span><span class="nx">style</span><span class="o">.</span><span class="nx">display</span> <span class="o">=</span> <span class="s2">&quot;block&quot;</span><span class="o">;</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">.</span><span class="nx">style</span><span class="o">.</span><span class="nx">display</span> <span class="o">=</span> <span class="s2">&quot;block&quot;</span><span class="o">;</span>
        <span class="o">}</span>
    <span class="o">}</span>
    <span class="k">else</span> <span class="o">{</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">.</span><span class="nx">_oBody</span><span class="o">.</span><span class="nx">innerHTML</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span><span class="o">;</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">.</span><span class="nx">style</span><span class="o">.</span><span class="nx">display</span> <span class="o">=</span> <span class="s2">&quot;none&quot;</span><span class="o">;</span>
    <span class="o">}</span>
    <span class="k">this</span><span class="o">.</span><span class="nx">_maxResultsDisplayed</span> <span class="o">=</span> <span class="m">0</span><span class="o">;</span>
<span class="o">};</span>

<span class="c">/**</span>
<span class="c"> * Overridable method that converts a result item object into HTML markup</span>
<span class="c"> * for display. Return data values are accessible via the oResultItem object,</span>
<span class="c"> * and the key return value will always be oResultItem[0]. Markup will be</span>
<span class="c"> * displayed within &amp;lt;li&amp;gt; element tags in the container.</span>
<span class="c"> *</span>
<span class="c"> * @method formatResult</span>
<span class="c"> * @param oResultItem {Object} Result item representing one query result. Data is held in an array.</span>
<span class="c"> * @param sQuery {String} The current query string.</span>
<span class="c"> * @return {String} HTML markup of formatted result data.</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">formatResult</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">oResultItem</span><span class="o">,</span> <span class="nx">sQuery</span><span class="o">)</span> <span class="o">{</span>
    <span class="k">var</span> <span class="nx">sResult</span> <span class="o">=</span> <span class="nx">oResultItem</span><span class="o">[</span><span class="m">0</span><span class="o">];</span>
    <span class="k">if</span><span class="o">(</span><span class="nx">sResult</span><span class="o">)</span> <span class="o">{</span>
        <span class="k">return</span> <span class="nx">sResult</span><span class="o">;</span>
    <span class="o">}</span>
    <span class="k">else</span> <span class="o">{</span>
        <span class="k">return</span> <span class="s2">&quot;&quot;</span><span class="o">;</span>
    <span class="o">}</span>
<span class="o">};</span>

<span class="c">/**</span>
<span class="c"> * Overridable method called before container expands allows implementers to access data</span>
<span class="c"> * and DOM elements.</span>
<span class="c"> *</span>
<span class="c"> * @method doBeforeExpandContainer</span>
<span class="c"> * @return {Boolean} Return true to continue expanding container, false to cancel the expand.</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">doBeforeExpandContainer</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">oResultItem</span><span class="o">,</span> <span class="nx">sQuery</span><span class="o">)</span> <span class="o">{</span>
    <span class="k">return</span> <span class="kc">true</span><span class="o">;</span>
<span class="o">};</span>

<span class="c">/**</span>
<span class="c"> * Makes query request to the DataSource.</span>
<span class="c"> *</span>
<span class="c"> * @method sendQuery</span>
<span class="c"> * @param sQuery {String} Query string.</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">sendQuery</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">sQuery</span><span class="o">)</span> <span class="o">{</span>
    <span class="k">this</span><span class="o">.</span><span class="nx">_sendQuery</span><span class="o">(</span><span class="nx">sQuery</span><span class="o">);</span>
<span class="o">};</span>

<span class="c">/////////////////////////////////////////////////////////////////////////////</span>
<span class="c">//</span>
<span class="c">// Public events</span>
<span class="c">//</span>
<span class="c">/////////////////////////////////////////////////////////////////////////////</span>
<span class="c"></span>
<span class="c">/**</span>
<span class="c"> * Fired when the input field receives focus.</span>
<span class="c"> *</span>
<span class="c"> * @event textboxFocusEvent</span>
<span class="c"> * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">textboxFocusEvent</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Fired when the input field receives key input.</span>
<span class="c"> *</span>
<span class="c"> * @event textboxKeyEvent</span>
<span class="c"> * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.</span>
<span class="c"> * @param nKeycode {Number} The keycode number.</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">textboxKeyEvent</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Fired when the AutoComplete instance makes a query to the DataSource.</span>
<span class="c"> * </span>
<span class="c"> * @event dataRequestEvent</span>
<span class="c"> * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.</span>
<span class="c"> * @param sQuery {String} The query string.</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">dataRequestEvent</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Fired when the AutoComplete instance receives query results from the data</span>
<span class="c"> * source.</span>
<span class="c"> *</span>
<span class="c"> * @event dataReturnEvent</span>
<span class="c"> * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.</span>
<span class="c"> * @param sQuery {String} The query string.</span>
<span class="c"> * @param aResults {Object[]} Results array.</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">dataReturnEvent</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Fired when the AutoComplete instance does not receive query results from the</span>
<span class="c"> * DataSource due to an error.</span>
<span class="c"> *</span>
<span class="c"> * @event dataErrorEvent</span>
<span class="c"> * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.</span>
<span class="c"> * @param sQuery {String} The query string.</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">dataErrorEvent</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Fired when the results container is expanded.</span>
<span class="c"> *</span>
<span class="c"> * @event containerExpandEvent</span>
<span class="c"> * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">containerExpandEvent</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Fired when the input field has been prefilled by the type-ahead</span>
<span class="c"> * feature. </span>
<span class="c"> *</span>
<span class="c"> * @event typeAheadEvent</span>
<span class="c"> * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.</span>
<span class="c"> * @param sQuery {String} The query string.</span>
<span class="c"> * @param sPrefill {String} The prefill string.</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">typeAheadEvent</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Fired when result item has been moused over.</span>
<span class="c"> *</span>
<span class="c"> * @event itemMouseOverEvent</span>
<span class="c"> * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.</span>
<span class="c"> * @param elItem {HTMLElement} The &amp;lt;li&amp;gt element item moused to.</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">itemMouseOverEvent</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Fired when result item has been moused out.</span>
<span class="c"> *</span>
<span class="c"> * @event itemMouseOutEvent</span>
<span class="c"> * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.</span>
<span class="c"> * @param elItem {HTMLElement} The &amp;lt;li&amp;gt; element item moused from.</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">itemMouseOutEvent</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Fired when result item has been arrowed to. </span>
<span class="c"> *</span>
<span class="c"> * @event itemArrowToEvent</span>
<span class="c"> * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.</span>
<span class="c"> * @param elItem {HTMLElement} The &amp;lt;li&amp;gt; element item arrowed to.</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">itemArrowToEvent</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Fired when result item has been arrowed away from.</span>
<span class="c"> *</span>
<span class="c"> * @event itemArrowFromEvent</span>
<span class="c"> * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.</span>
<span class="c"> * @param elItem {HTMLElement} The &amp;lt;li&amp;gt; element item arrowed from.</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">itemArrowFromEvent</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Fired when an item is selected via mouse click, ENTER key, or TAB key.</span>
<span class="c"> *</span>
<span class="c"> * @event itemSelectEvent</span>
<span class="c"> * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.</span>
<span class="c"> * @param elItem {HTMLElement} The selected &amp;lt;li&amp;gt; element item.</span>
<span class="c"> * @param oData {Object} The data returned for the item, either as an object,</span>
<span class="c"> * or mapped from the schema into an array.</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">itemSelectEvent</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Fired when a user selection does not match any of the displayed result items.</span>
<span class="c"> * Note that this event may not behave as expected when delimiter characters</span>
<span class="c"> * have been defined. </span>
<span class="c"> *</span>
<span class="c"> * @event unmatchedItemSelectEvent</span>
<span class="c"> * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.</span>
<span class="c"> * @param sQuery {String} The user-typed query string.</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">unmatchedItemSelectEvent</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Fired if forceSelection is enabled and the user&#39;s input has been cleared</span>
<span class="c"> * because it did not match one of the returned query results.</span>
<span class="c"> *</span>
<span class="c"> * @event selectionEnforceEvent</span>
<span class="c"> * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">selectionEnforceEvent</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Fired when the results container is collapsed.</span>
<span class="c"> *</span>
<span class="c"> * @event containerCollapseEvent</span>
<span class="c"> * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">containerCollapseEvent</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Fired when the input field loses focus.</span>
<span class="c"> *</span>
<span class="c"> * @event textboxBlurEvent</span>
<span class="c"> * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">textboxBlurEvent</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>

<span class="c">/////////////////////////////////////////////////////////////////////////////</span>
<span class="c">//</span>
<span class="c">// Private member variables</span>
<span class="c">//</span>
<span class="c">/////////////////////////////////////////////////////////////////////////////</span>
<span class="c"></span>
<span class="c">/**</span>
<span class="c"> * Internal class variable to index multiple AutoComplete instances.</span>
<span class="c"> *</span>
<span class="c"> * @property _nIndex</span>
<span class="c"> * @type Number</span>
<span class="c"> * @default 0</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">_nIndex</span> <span class="o">=</span> <span class="m">0</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Name of AutoComplete instance.</span>
<span class="c"> *</span>
<span class="c"> * @property _sName</span>
<span class="c"> * @type String</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_sName</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Text input field DOM element.</span>
<span class="c"> *</span>
<span class="c"> * @property _oTextbox</span>
<span class="c"> * @type HTMLElement</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_oTextbox</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Whether or not the input field is currently in focus. If query results come back</span>
<span class="c"> * but the user has already moved on, do not proceed with auto complete behavior.</span>
<span class="c"> *</span>
<span class="c"> * @property _bFocused</span>
<span class="c"> * @type Boolean</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_bFocused</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Animation instance for container expand/collapse.</span>
<span class="c"> *</span>
<span class="c"> * @property _oAnim</span>
<span class="c"> * @type Boolean</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_oAnim</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Container DOM element.</span>
<span class="c"> *</span>
<span class="c"> * @property _oContainer</span>
<span class="c"> * @type HTMLElement</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_oContainer</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Whether or not the results container is currently open.</span>
<span class="c"> *</span>
<span class="c"> * @property _bContainerOpen</span>
<span class="c"> * @type Boolean</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_bContainerOpen</span> <span class="o">=</span> <span class="kc">false</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Whether or not the mouse is currently over the results</span>
<span class="c"> * container. This is necessary in order to prevent clicks on container items</span>
<span class="c"> * from being text input field blur events.</span>
<span class="c"> *</span>
<span class="c"> * @property _bOverContainer</span>
<span class="c"> * @type Boolean</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_bOverContainer</span> <span class="o">=</span> <span class="kc">false</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Array of &amp;lt;li&amp;gt; elements references that contain query results within the</span>
<span class="c"> * results container.</span>
<span class="c"> *</span>
<span class="c"> * @property _aListItems</span>
<span class="c"> * @type HTMLElement[]</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_aListItems</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Number of &amp;lt;li&amp;gt; elements currently displayed in results container.</span>
<span class="c"> *</span>
<span class="c"> * @property _nDisplayedItems</span>
<span class="c"> * @type Number</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_nDisplayedItems</span> <span class="o">=</span> <span class="m">0</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Internal count of &amp;lt;li&amp;gt; elements displayed and hidden in results container.</span>
<span class="c"> *</span>
<span class="c"> * @property _maxResultsDisplayed</span>
<span class="c"> * @type Number</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_maxResultsDisplayed</span> <span class="o">=</span> <span class="m">0</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Current query string</span>
<span class="c"> *</span>
<span class="c"> * @property _sCurQuery</span>
<span class="c"> * @type String</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_sCurQuery</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Past queries this session (for saving delimited queries).</span>
<span class="c"> *</span>
<span class="c"> * @property _sSavedQuery</span>
<span class="c"> * @type String</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_sSavedQuery</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Pointer to the currently highlighted &amp;lt;li&amp;gt; element in the container.</span>
<span class="c"> *</span>
<span class="c"> * @property _oCurItem</span>
<span class="c"> * @type HTMLElement</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_oCurItem</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Whether or not an item has been selected since the container was populated</span>
<span class="c"> * with results. Reset to false by _populateList, and set to true when item is</span>
<span class="c"> * selected.</span>
<span class="c"> *</span>
<span class="c"> * @property _bItemSelected</span>
<span class="c"> * @type Boolean</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_bItemSelected</span> <span class="o">=</span> <span class="kc">false</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Key code of the last key pressed in textbox.</span>
<span class="c"> *</span>
<span class="c"> * @property _nKeyCode</span>
<span class="c"> * @type Number</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_nKeyCode</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Delay timeout ID.</span>
<span class="c"> *</span>
<span class="c"> * @property _nDelayID</span>
<span class="c"> * @type Number</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_nDelayID</span> <span class="o">=</span> <span class="o">-</span><span class="m">1</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Src to iFrame used when useIFrame = true. Supports implementations over SSL</span>
<span class="c"> * as well.</span>
<span class="c"> *</span>
<span class="c"> * @property _iFrameSrc</span>
<span class="c"> * @type String</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_iFrameSrc</span> <span class="o">=</span> <span class="s2">&quot;javascript:false;&quot;</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * For users typing via certain IMEs, queries must be triggered by intervals,</span>
<span class="c"> * since key events yet supported across all browsers for all IMEs.</span>
<span class="c"> *</span>
<span class="c"> * @property _queryInterval</span>
<span class="c"> * @type Object</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_queryInterval</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>

<span class="c">/**</span>
<span class="c"> * Internal tracker to last known textbox value, used to determine whether or not</span>
<span class="c"> * to trigger a query via interval for certain IME users.</span>
<span class="c"> *</span>
<span class="c"> * @event _sLastTextboxValue</span>
<span class="c"> * @type String</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_sLastTextboxValue</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>

<span class="c">/////////////////////////////////////////////////////////////////////////////</span>
<span class="c">//</span>
<span class="c">// Private methods</span>
<span class="c">//</span>
<span class="c">/////////////////////////////////////////////////////////////////////////////</span>
<span class="c"></span>
<span class="c">/**</span>
<span class="c"> * Updates and validates latest public config properties.</span>
<span class="c"> *</span>
<span class="c"> * @method __initProps</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_initProps</span> <span class="o">=</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
    <span class="c">// Correct any invalid values</span>
<span class="c"></span>    <span class="k">var</span> <span class="nx">minQueryLength</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">minQueryLength</span><span class="o">;</span>
    <span class="k">if</span><span class="o">(!</span><span class="nx">YAHOO</span><span class="o">.</span><span class="nx">lang</span><span class="o">.</span><span class="nx">isNumber</span><span class="o">(</span><span class="nx">minQueryLength</span><span class="o">)</span> <span class="o">||</span> <span class="o">(</span><span class="nx">minQueryLength</span> <span class="o">&lt;</span> <span class="m">1</span><span class="o">))</span> <span class="o">{</span>
        <span class="nx">minQueryLength</span> <span class="o">=</span> <span class="m">1</span><span class="o">;</span>
    <span class="o">}</span>
    <span class="k">var</span> <span class="nx">maxResultsDisplayed</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">maxResultsDisplayed</span><span class="o">;</span>
    <span class="k">if</span><span class="o">(!</span><span class="nx">YAHOO</span><span class="o">.</span><span class="nx">lang</span><span class="o">.</span><span class="nx">isNumber</span><span class="o">(</span><span class="nx">maxResultsDisplayed</span><span class="o">)</span> <span class="o">||</span> <span class="o">(</span><span class="nx">maxResultsDisplayed</span> <span class="o">&lt;</span> <span class="m">1</span><span class="o">))</span> <span class="o">{</span>
        <span class="nx">maxResultsDisplayed</span> <span class="o">=</span> <span class="m">10</span><span class="o">;</span>
    <span class="o">}</span>
    <span class="k">var</span> <span class="nx">queryDelay</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">queryDelay</span><span class="o">;</span>
    <span class="k">if</span><span class="o">(!</span><span class="nx">YAHOO</span><span class="o">.</span><span class="nx">lang</span><span class="o">.</span><span class="nx">isNumber</span><span class="o">(</span><span class="nx">queryDelay</span><span class="o">)</span> <span class="o">||</span> <span class="o">(</span><span class="nx">queryDelay</span> <span class="o">&lt;</span> <span class="m">0</span><span class="o">))</span> <span class="o">{</span>
        <span class="nx">queryDelay</span> <span class="o">=</span> <span class="m">0</span><span class="o">.</span><span class="m">5</span><span class="o">;</span>
    <span class="o">}</span>
    <span class="k">var</span> <span class="nx">delimChar</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">delimChar</span><span class="o">;</span>
    <span class="k">if</span><span class="o">(</span><span class="nx">YAHOO</span><span class="o">.</span><span class="nx">lang</span><span class="o">.</span><span class="nx">isString</span><span class="o">(</span><span class="nx">delimChar</span><span class="o">))</span> <span class="o">{</span>
        <span class="nx">delimChar</span> <span class="o">=</span> <span class="o">[</span><span class="nx">delimChar</span><span class="o">];</span>
    <span class="o">}</span>
    <span class="k">else</span> <span class="k">if</span><span class="o">(!</span><span class="nx">YAHOO</span><span class="o">.</span><span class="nx">lang</span><span class="o">.</span><span class="nx">isArray</span><span class="o">(</span><span class="nx">delimChar</span><span class="o">))</span> <span class="o">{</span>
        <span class="nx">delimChar</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>
    <span class="o">}</span>
    <span class="k">var</span> <span class="nx">animSpeed</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">animSpeed</span><span class="o">;</span>
    <span class="k">if</span><span class="o">((</span><span class="k">this</span><span class="o">.</span><span class="nx">animHoriz</span> <span class="o">||</span> <span class="k">this</span><span class="o">.</span><span class="nx">animVert</span><span class="o">)</span> <span class="o">&amp;&amp;</span> <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">Anim</span><span class="o">)</span> <span class="o">{</span>
        <span class="k">if</span><span class="o">(!</span><span class="nx">YAHOO</span><span class="o">.</span><span class="nx">lang</span><span class="o">.</span><span class="nx">isNumber</span><span class="o">(</span><span class="nx">animSpeed</span><span class="o">)</span> <span class="o">||</span> <span class="o">(</span><span class="nx">animSpeed</span> <span class="o">&lt;</span> <span class="m">0</span><span class="o">))</span> <span class="o">{</span>
            <span class="nx">animSpeed</span> <span class="o">=</span> <span class="m">0</span><span class="o">.</span><span class="m">3</span><span class="o">;</span>
        <span class="o">}</span>
        <span class="k">if</span><span class="o">(!</span><span class="k">this</span><span class="o">.</span><span class="nx">_oAnim</span> <span class="o">)</span> <span class="o">{</span>
            <span class="nx">oAnim</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">Anim</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">,</span> <span class="o">{},</span> <span class="nx">animSpeed</span><span class="o">);</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">_oAnim</span> <span class="o">=</span> <span class="nx">oAnim</span><span class="o">;</span>
        <span class="o">}</span>
        <span class="k">else</span> <span class="o">{</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">_oAnim</span><span class="o">.</span><span class="nx">duration</span> <span class="o">=</span> <span class="nx">animSpeed</span><span class="o">;</span>
        <span class="o">}</span>
    <span class="o">}</span>
    <span class="k">if</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">forceSelection</span> <span class="o">&amp;&amp;</span> <span class="nx">delimChar</span><span class="o">)</span> <span class="o">{</span>
        <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s2">&quot;The forceSelection feature has been enabled with delimChar defined.&quot;</span><span class="o">,</span><span class="s2">&quot;warn&quot;</span><span class="o">,</span> <span class="k">this</span><span class="o">.</span><span class="nx">toString</span><span class="o">());</span>
    <span class="o">}</span>
<span class="o">};</span>

<span class="c">/**</span>
<span class="c"> * Initializes the results container helpers if they are enabled and do</span>
<span class="c"> * not exist</span>
<span class="c"> *</span>
<span class="c"> * @method _initContainerHelpers</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_initContainerHelpers</span> <span class="o">=</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
    <span class="k">if</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">useShadow</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oShadow</span><span class="o">)</span> <span class="o">{</span>
        <span class="k">var</span> <span class="nx">oShadow</span> <span class="o">=</span> <span class="nb">document</span><span class="o">.</span><span class="nx">createElement</span><span class="o">(</span><span class="s2">&quot;div&quot;</span><span class="o">);</span>
        <span class="nx">oShadow</span><span class="o">.</span><span class="nx">className</span> <span class="o">=</span> <span class="s2">&quot;yui-ac-shadow&quot;</span><span class="o">;</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oShadow</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">appendChild</span><span class="o">(</span><span class="nx">oShadow</span><span class="o">);</span>
    <span class="o">}</span>
    <span class="k">if</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">useIFrame</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oIFrame</span><span class="o">)</span> <span class="o">{</span>
        <span class="k">var</span> <span class="nx">oIFrame</span> <span class="o">=</span> <span class="nb">document</span><span class="o">.</span><span class="nx">createElement</span><span class="o">(</span><span class="s2">&quot;iframe&quot;</span><span class="o">);</span>
        <span class="nx">oIFrame</span><span class="o">.</span><span class="nx">src</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_iFrameSrc</span><span class="o">;</span>
        <span class="nx">oIFrame</span><span class="o">.</span><span class="nx">frameBorder</span> <span class="o">=</span> <span class="m">0</span><span class="o">;</span>
        <span class="nx">oIFrame</span><span class="o">.</span><span class="nx">scrolling</span> <span class="o">=</span> <span class="s2">&quot;no&quot;</span><span class="o">;</span>
        <span class="nx">oIFrame</span><span class="o">.</span><span class="nx">style</span><span class="o">.</span><span class="nx">position</span> <span class="o">=</span> <span class="s2">&quot;absolute&quot;</span><span class="o">;</span>
        <span class="nx">oIFrame</span><span class="o">.</span><span class="nx">style</span><span class="o">.</span><span class="nx">width</span> <span class="o">=</span> <span class="s2">&quot;100%&quot;</span><span class="o">;</span>
        <span class="nx">oIFrame</span><span class="o">.</span><span class="nx">style</span><span class="o">.</span><span class="nx">height</span> <span class="o">=</span> <span class="s2">&quot;100%&quot;</span><span class="o">;</span>
        <span class="nx">oIFrame</span><span class="o">.</span><span class="nx">tabIndex</span> <span class="o">=</span> <span class="o">-</span><span class="m">1</span><span class="o">;</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oIFrame</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">appendChild</span><span class="o">(</span><span class="nx">oIFrame</span><span class="o">);</span>
    <span class="o">}</span>
<span class="o">};</span>

<span class="c">/**</span>
<span class="c"> * Initializes the results container once at object creation</span>
<span class="c"> *</span>
<span class="c"> * @method _initContainer</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_initContainer</span> <span class="o">=</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
    <span class="k">if</span><span class="o">(!</span><span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">)</span> <span class="o">{</span>
        <span class="c">// The oContent div helps size the iframe and shadow properly</span>
<span class="c"></span>        <span class="k">var</span> <span class="nx">oContent</span> <span class="o">=</span> <span class="nb">document</span><span class="o">.</span><span class="nx">createElement</span><span class="o">(</span><span class="s2">&quot;div&quot;</span><span class="o">);</span>
        <span class="nx">oContent</span><span class="o">.</span><span class="nx">className</span> <span class="o">=</span> <span class="s2">&quot;yui-ac-content&quot;</span><span class="o">;</span>
        <span class="nx">oContent</span><span class="o">.</span><span class="nx">style</span><span class="o">.</span><span class="nx">display</span> <span class="o">=</span> <span class="s2">&quot;none&quot;</span><span class="o">;</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oContent</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">appendChild</span><span class="o">(</span><span class="nx">oContent</span><span class="o">);</span>

        <span class="k">var</span> <span class="nx">oHeader</span> <span class="o">=</span> <span class="nb">document</span><span class="o">.</span><span class="nx">createElement</span><span class="o">(</span><span class="s2">&quot;div&quot;</span><span class="o">);</span>
        <span class="nx">oHeader</span><span class="o">.</span><span class="nx">className</span> <span class="o">=</span> <span class="s2">&quot;yui-ac-hd&quot;</span><span class="o">;</span>
        <span class="nx">oHeader</span><span class="o">.</span><span class="nx">style</span><span class="o">.</span><span class="nx">display</span> <span class="o">=</span> <span class="s2">&quot;none&quot;</span><span class="o">;</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">.</span><span class="nx">_oHeader</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">.</span><span class="nx">appendChild</span><span class="o">(</span><span class="nx">oHeader</span><span class="o">);</span>

        <span class="k">var</span> <span class="nx">oBody</span> <span class="o">=</span> <span class="nb">document</span><span class="o">.</span><span class="nx">createElement</span><span class="o">(</span><span class="s2">&quot;div&quot;</span><span class="o">);</span>
        <span class="nx">oBody</span><span class="o">.</span><span class="nx">className</span> <span class="o">=</span> <span class="s2">&quot;yui-ac-bd&quot;</span><span class="o">;</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">.</span><span class="nx">_oBody</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">.</span><span class="nx">appendChild</span><span class="o">(</span><span class="nx">oBody</span><span class="o">);</span>

        <span class="k">var</span> <span class="nx">oFooter</span> <span class="o">=</span> <span class="nb">document</span><span class="o">.</span><span class="nx">createElement</span><span class="o">(</span><span class="s2">&quot;div&quot;</span><span class="o">);</span>
        <span class="nx">oFooter</span><span class="o">.</span><span class="nx">className</span> <span class="o">=</span> <span class="s2">&quot;yui-ac-ft&quot;</span><span class="o">;</span>
        <span class="nx">oFooter</span><span class="o">.</span><span class="nx">style</span><span class="o">.</span><span class="nx">display</span> <span class="o">=</span> <span class="s2">&quot;none&quot;</span><span class="o">;</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">.</span><span class="nx">_oFooter</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">.</span><span class="nx">appendChild</span><span class="o">(</span><span class="nx">oFooter</span><span class="o">);</span>
    <span class="o">}</span>
    <span class="k">else</span> <span class="o">{</span>
        <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s2">&quot;Could not initialize the container&quot;</span><span class="o">,</span><span class="s2">&quot;warn&quot;</span><span class="o">,</span><span class="k">this</span><span class="o">.</span><span class="nx">toString</span><span class="o">());</span>
    <span class="o">}</span>
<span class="o">};</span>

<span class="c">/**</span>
<span class="c"> * Clears out contents of container body and creates up to</span>
<span class="c"> * YAHOO.widget.AutoComplete#maxResultsDisplayed &amp;lt;li&amp;gt; elements in an</span>
<span class="c"> * &amp;lt;ul&amp;gt; element.</span>
<span class="c"> *</span>
<span class="c"> * @method _initList</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_initList</span> <span class="o">=</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
    <span class="k">this</span><span class="o">.</span><span class="nx">_aListItems</span> <span class="o">=</span> <span class="o">[];</span>
    <span class="k">while</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">.</span><span class="nx">_oBody</span><span class="o">.</span><span class="nx">hasChildNodes</span><span class="o">())</span> <span class="o">{</span>
        <span class="k">var</span> <span class="nx">oldListItems</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">getListItems</span><span class="o">();</span>
        <span class="k">if</span><span class="o">(</span><span class="nx">oldListItems</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">for</span><span class="o">(</span><span class="k">var</span> <span class="nx">oldi</span> <span class="o">=</span> <span class="nx">oldListItems</span><span class="o">.</span><span class="nx">length</span><span class="o">-</span><span class="m">1</span><span class="o">;</span> <span class="nx">oldi</span> <span class="o">&gt;=</span> <span class="m">0</span><span class="o">;</span> <span class="nx">oldi</span><span class="o">--)</span> <span class="o">{</span>
                <span class="nx">oldListItems</span><span class="o">[</span><span class="nx">oldi</span><span class="o">]</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>
            <span class="o">}</span>
        <span class="o">}</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">.</span><span class="nx">_oBody</span><span class="o">.</span><span class="nx">innerHTML</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span><span class="o">;</span>
    <span class="o">}</span>

    <span class="k">var</span> <span class="nx">oList</span> <span class="o">=</span> <span class="nb">document</span><span class="o">.</span><span class="nx">createElement</span><span class="o">(</span><span class="s2">&quot;ul&quot;</span><span class="o">);</span>
    <span class="nx">oList</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">.</span><span class="nx">_oBody</span><span class="o">.</span><span class="nx">appendChild</span><span class="o">(</span><span class="nx">oList</span><span class="o">);</span>
    <span class="k">for</span><span class="o">(</span><span class="k">var</span> <span class="nx">i</span><span class="o">=</span><span class="m">0</span><span class="o">;</span> <span class="nx">i</span><span class="o">&lt;</span><span class="k">this</span><span class="o">.</span><span class="nx">maxResultsDisplayed</span><span class="o">;</span> <span class="nx">i</span><span class="o">++)</span> <span class="o">{</span>
        <span class="k">var</span> <span class="nx">oItem</span> <span class="o">=</span> <span class="nb">document</span><span class="o">.</span><span class="nx">createElement</span><span class="o">(</span><span class="s2">&quot;li&quot;</span><span class="o">);</span>
        <span class="nx">oItem</span> <span class="o">=</span> <span class="nx">oList</span><span class="o">.</span><span class="nx">appendChild</span><span class="o">(</span><span class="nx">oItem</span><span class="o">);</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">_aListItems</span><span class="o">[</span><span class="nx">i</span><span class="o">]</span> <span class="o">=</span> <span class="nx">oItem</span><span class="o">;</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">_initListItem</span><span class="o">(</span><span class="nx">oItem</span><span class="o">,</span> <span class="nx">i</span><span class="o">);</span>
    <span class="o">}</span>
    <span class="k">this</span><span class="o">.</span><span class="nx">_maxResultsDisplayed</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">maxResultsDisplayed</span><span class="o">;</span>
<span class="o">};</span>

<span class="c">/**</span>
<span class="c"> * Initializes each &amp;lt;li&amp;gt; element in the container list.</span>
<span class="c"> *</span>
<span class="c"> * @method _initListItem</span>
<span class="c"> * @param oItem {HTMLElement} The &amp;lt;li&amp;gt; DOM element.</span>
<span class="c"> * @param nItemIndex {Number} The index of the element.</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_initListItem</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">oItem</span><span class="o">,</span> <span class="nx">nItemIndex</span><span class="o">)</span> <span class="o">{</span>
    <span class="k">var</span> <span class="nx">oSelf</span> <span class="o">=</span> <span class="k">this</span><span class="o">;</span>
    <span class="nx">oItem</span><span class="o">.</span><span class="nx">style</span><span class="o">.</span><span class="nx">display</span> <span class="o">=</span> <span class="s2">&quot;none&quot;</span><span class="o">;</span>
    <span class="nx">oItem</span><span class="o">.</span><span class="nx">_nItemIndex</span> <span class="o">=</span> <span class="nx">nItemIndex</span><span class="o">;</span>

    <span class="nx">oItem</span><span class="o">.</span><span class="nx">mouseover</span> <span class="o">=</span> <span class="nx">oItem</span><span class="o">.</span><span class="nx">mouseout</span> <span class="o">=</span> <span class="nx">oItem</span><span class="o">.</span><span class="nx">onclick</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>
    <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">Event</span><span class="o">.</span><span class="nx">addListener</span><span class="o">(</span><span class="nx">oItem</span><span class="o">,</span><span class="s2">&quot;mouseover&quot;</span><span class="o">,</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_onItemMouseover</span><span class="o">,</span><span class="nx">oSelf</span><span class="o">);</span>
    <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">Event</span><span class="o">.</span><span class="nx">addListener</span><span class="o">(</span><span class="nx">oItem</span><span class="o">,</span><span class="s2">&quot;mouseout&quot;</span><span class="o">,</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_onItemMouseout</span><span class="o">,</span><span class="nx">oSelf</span><span class="o">);</span>
    <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">Event</span><span class="o">.</span><span class="nx">addListener</span><span class="o">(</span><span class="nx">oItem</span><span class="o">,</span><span class="s2">&quot;click&quot;</span><span class="o">,</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_onItemMouseclick</span><span class="o">,</span><span class="nx">oSelf</span><span class="o">);</span>
<span class="o">};</span>

<span class="c">/**</span>
<span class="c"> * Enables interval detection for  Korean IME support.</span>
<span class="c"> *</span>
<span class="c"> * @method _onIMEDetected</span>
<span class="c"> * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_onIMEDetected</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">oSelf</span><span class="o">)</span> <span class="o">{</span>
    <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_enableIntervalDetection</span><span class="o">();</span>
<span class="o">};</span>

<span class="c">/**</span>
<span class="c"> * Enables query triggers based on text input detection by intervals (rather</span>
<span class="c"> * than by key events).</span>
<span class="c"> *</span>
<span class="c"> * @method _enableIntervalDetection</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_enableIntervalDetection</span> <span class="o">=</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
    <span class="k">var</span> <span class="nx">currValue</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_oTextbox</span><span class="o">.</span><span class="nx">value</span><span class="o">;</span>
    <span class="k">var</span> <span class="nx">lastValue</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_sLastTextboxValue</span><span class="o">;</span>
    <span class="k">if</span><span class="o">(</span><span class="nx">currValue</span> <span class="o">!=</span> <span class="nx">lastValue</span><span class="o">)</span> <span class="o">{</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">_sLastTextboxValue</span> <span class="o">=</span> <span class="nx">currValue</span><span class="o">;</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">_sendQuery</span><span class="o">(</span><span class="nx">currValue</span><span class="o">);</span>
    <span class="o">}</span>
<span class="o">};</span>


<span class="c">/**</span>
<span class="c"> * Cancels text input detection by intervals.</span>
<span class="c"> *</span>
<span class="c"> * @method _cancelIntervalDetection</span>
<span class="c"> * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_cancelIntervalDetection</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">oSelf</span><span class="o">)</span> <span class="o">{</span>
    <span class="k">if</span><span class="o">(</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_queryInterval</span><span class="o">)</span> <span class="o">{</span>
        <span class="nx">clearInterval</span><span class="o">(</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_queryInterval</span><span class="o">);</span>
    <span class="o">}</span>
<span class="o">};</span>


<span class="c">/**</span>
<span class="c"> * Whether or not key is functional or should be ignored. Note that the right</span>
<span class="c"> * arrow key is NOT an ignored key since it triggers queries for certain intl</span>
<span class="c"> * charsets.</span>
<span class="c"> *</span>
<span class="c"> * @method _isIgnoreKey</span>
<span class="c"> * @param nKeycode {Number} Code of key pressed.</span>
<span class="c"> * @return {Boolean} True if key should be ignored, false otherwise.</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_isIgnoreKey</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">nKeyCode</span><span class="o">)</span> <span class="o">{</span>
    <span class="k">if</span><span class="o">((</span><span class="nx">nKeyCode</span> <span class="o">==</span> <span class="m">9</span><span class="o">)</span> <span class="o">||</span> <span class="o">(</span><span class="nx">nKeyCode</span> <span class="o">==</span> <span class="m">13</span><span class="o">)</span>  <span class="o">||</span> <span class="c">// tab, enter</span>
<span class="c"></span>            <span class="o">(</span><span class="nx">nKeyCode</span> <span class="o">==</span> <span class="m">16</span><span class="o">)</span> <span class="o">||</span> <span class="o">(</span><span class="nx">nKeyCode</span> <span class="o">==</span> <span class="m">17</span><span class="o">)</span> <span class="o">||</span> <span class="c">// shift, ctl</span>
<span class="c"></span>            <span class="o">(</span><span class="nx">nKeyCode</span> <span class="o">&gt;=</span> <span class="m">18</span> <span class="o">&amp;&amp;</span> <span class="nx">nKeyCode</span> <span class="o">&lt;=</span> <span class="m">20</span><span class="o">)</span> <span class="o">||</span> <span class="c">// alt,pause/break,caps lock</span>
<span class="c"></span>            <span class="o">(</span><span class="nx">nKeyCode</span> <span class="o">==</span> <span class="m">27</span><span class="o">)</span> <span class="o">||</span> <span class="c">// esc</span>
<span class="c"></span>            <span class="o">(</span><span class="nx">nKeyCode</span> <span class="o">&gt;=</span> <span class="m">33</span> <span class="o">&amp;&amp;</span> <span class="nx">nKeyCode</span> <span class="o">&lt;=</span> <span class="m">35</span><span class="o">)</span> <span class="o">||</span> <span class="c">// page up,page down,end</span>
<span class="c"></span>            <span class="o">(</span><span class="nx">nKeyCode</span> <span class="o">&gt;=</span> <span class="m">36</span> <span class="o">&amp;&amp;</span> <span class="nx">nKeyCode</span> <span class="o">&lt;=</span> <span class="m">38</span><span class="o">)</span> <span class="o">||</span> <span class="c">// home,left,up</span>
<span class="c"></span>            <span class="o">(</span><span class="nx">nKeyCode</span> <span class="o">==</span> <span class="m">40</span><span class="o">)</span> <span class="o">||</span> <span class="c">// down</span>
<span class="c"></span>            <span class="o">(</span><span class="nx">nKeyCode</span> <span class="o">&gt;=</span> <span class="m">44</span> <span class="o">&amp;&amp;</span> <span class="nx">nKeyCode</span> <span class="o">&lt;=</span> <span class="m">45</span><span class="o">))</span> <span class="o">{</span> <span class="c">// print screen,insert</span>
<span class="c"></span>        <span class="k">return</span> <span class="kc">true</span><span class="o">;</span>
    <span class="o">}</span>
    <span class="k">return</span> <span class="kc">false</span><span class="o">;</span>
<span class="o">};</span>

<span class="c">/**</span>
<span class="c"> * Makes query request to the DataSource.</span>
<span class="c"> *</span>
<span class="c"> * @method _sendQuery</span>
<span class="c"> * @param sQuery {String} Query string.</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_sendQuery</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">sQuery</span><span class="o">)</span> <span class="o">{</span>
    <span class="c">// Widget has been effectively turned off</span>
<span class="c"></span>    <span class="k">if</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">minQueryLength</span> <span class="o">==</span> <span class="o">-</span><span class="m">1</span><span class="o">)</span> <span class="o">{</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">_toggleContainer</span><span class="o">(</span><span class="kc">false</span><span class="o">);</span>
        <span class="k">return</span><span class="o">;</span>
    <span class="o">}</span>
    <span class="c">// Delimiter has been enabled</span>
<span class="c"></span>    <span class="k">var</span> <span class="nx">aDelimChar</span> <span class="o">=</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">delimChar</span><span class="o">)</span> <span class="o">?</span> <span class="k">this</span><span class="o">.</span><span class="nx">delimChar</span> <span class="o">:</span> <span class="kc">null</span><span class="o">;</span>
    <span class="k">if</span><span class="o">(</span><span class="nx">aDelimChar</span><span class="o">)</span> <span class="o">{</span>
        <span class="c">// Loop through all possible delimiters and find the latest one</span>
<span class="c"></span>        <span class="c">// A &quot; &quot; may be a false positive if they are defined as delimiters AND</span>
<span class="c"></span>        <span class="c">// are used to separate delimited queries</span>
<span class="c"></span>        <span class="k">var</span> <span class="nx">nDelimIndex</span> <span class="o">=</span> <span class="o">-</span><span class="m">1</span><span class="o">;</span>
        <span class="k">for</span><span class="o">(</span><span class="k">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="nx">aDelimChar</span><span class="o">.</span><span class="nx">length</span><span class="o">-</span><span class="m">1</span><span class="o">;</span> <span class="nx">i</span> <span class="o">&gt;=</span> <span class="m">0</span><span class="o">;</span> <span class="nx">i</span><span class="o">--)</span> <span class="o">{</span>
            <span class="k">var</span> <span class="nx">nNewIndex</span> <span class="o">=</span> <span class="nx">sQuery</span><span class="o">.</span><span class="nx">lastIndexOf</span><span class="o">(</span><span class="nx">aDelimChar</span><span class="o">[</span><span class="nx">i</span><span class="o">]);</span>
            <span class="k">if</span><span class="o">(</span><span class="nx">nNewIndex</span> <span class="o">&gt;</span> <span class="nx">nDelimIndex</span><span class="o">)</span> <span class="o">{</span>
                <span class="nx">nDelimIndex</span> <span class="o">=</span> <span class="nx">nNewIndex</span><span class="o">;</span>
            <span class="o">}</span>
        <span class="o">}</span>
        <span class="c">// If we think the last delimiter is a space (&quot; &quot;), make sure it is NOT</span>
<span class="c"></span>        <span class="c">// a false positive by also checking the char directly before it</span>
<span class="c"></span>        <span class="k">if</span><span class="o">(</span><span class="nx">aDelimChar</span><span class="o">[</span><span class="nx">i</span><span class="o">]</span> <span class="o">==</span> <span class="s2">&quot; &quot;</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">for</span> <span class="o">(</span><span class="k">var</span> <span class="nx">j</span> <span class="o">=</span> <span class="nx">aDelimChar</span><span class="o">.</span><span class="nx">length</span><span class="o">-</span><span class="m">1</span><span class="o">;</span> <span class="nx">j</span> <span class="o">&gt;=</span> <span class="m">0</span><span class="o">;</span> <span class="nx">j</span><span class="o">--)</span> <span class="o">{</span>
                <span class="k">if</span><span class="o">(</span><span class="nx">sQuery</span><span class="o">[</span><span class="nx">nDelimIndex</span> <span class="o">-</span> <span class="m">1</span><span class="o">]</span> <span class="o">==</span> <span class="nx">aDelimChar</span><span class="o">[</span><span class="nx">j</span><span class="o">])</span> <span class="o">{</span>
                    <span class="nx">nDelimIndex</span><span class="o">--;</span>
                    <span class="k">break</span><span class="o">;</span>
                <span class="o">}</span>
            <span class="o">}</span>
        <span class="o">}</span>
        <span class="c">// A delimiter has been found so extract the latest query</span>
<span class="c"></span>        <span class="k">if</span><span class="o">(</span><span class="nx">nDelimIndex</span> <span class="o">&gt;</span> <span class="o">-</span><span class="m">1</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">var</span> <span class="nx">nQueryStart</span> <span class="o">=</span> <span class="nx">nDelimIndex</span> <span class="o">+</span> <span class="m">1</span><span class="o">;</span>
            <span class="c">// Trim any white space from the beginning...</span>
<span class="c"></span>            <span class="k">while</span><span class="o">(</span><span class="nx">sQuery</span><span class="o">.</span><span class="nx">charAt</span><span class="o">(</span><span class="nx">nQueryStart</span><span class="o">)</span> <span class="o">==</span> <span class="s2">&quot; &quot;</span><span class="o">)</span> <span class="o">{</span>
                <span class="nx">nQueryStart</span> <span class="o">+=</span> <span class="m">1</span><span class="o">;</span>
            <span class="o">}</span>
            <span class="c">// ...and save the rest of the string for later</span>
<span class="c"></span>            <span class="k">this</span><span class="o">.</span><span class="nx">_sSavedQuery</span> <span class="o">=</span> <span class="nx">sQuery</span><span class="o">.</span><span class="nx">substring</span><span class="o">(</span><span class="m">0</span><span class="o">,</span><span class="nx">nQueryStart</span><span class="o">);</span>
            <span class="c">// Here is the query itself</span>
<span class="c"></span>            <span class="nx">sQuery</span> <span class="o">=</span> <span class="nx">sQuery</span><span class="o">.</span><span class="nx">substr</span><span class="o">(</span><span class="nx">nQueryStart</span><span class="o">);</span>
        <span class="o">}</span>
        <span class="k">else</span> <span class="k">if</span><span class="o">(</span><span class="nx">sQuery</span><span class="o">.</span><span class="nx">indexOf</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">_sSavedQuery</span><span class="o">)</span> <span class="o">&lt;</span> <span class="m">0</span><span class="o">){</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">_sSavedQuery</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>
        <span class="o">}</span>
    <span class="o">}</span>

    <span class="c">// Don&#39;t search queries that are too short</span>
<span class="c"></span>    <span class="k">if</span><span class="o">(</span><span class="nx">sQuery</span> <span class="o">&amp;&amp;</span> <span class="o">(</span><span class="nx">sQuery</span><span class="o">.</span><span class="nx">length</span> <span class="o">&lt;</span> <span class="k">this</span><span class="o">.</span><span class="nx">minQueryLength</span><span class="o">)</span> <span class="o">||</span> <span class="o">(!</span><span class="nx">sQuery</span> <span class="o">&amp;&amp;</span> <span class="k">this</span><span class="o">.</span><span class="nx">minQueryLength</span> <span class="o">&gt;</span> <span class="m">0</span><span class="o">))</span> <span class="o">{</span>
        <span class="k">if</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">_nDelayID</span> <span class="o">!=</span> <span class="o">-</span><span class="m">1</span><span class="o">)</span> <span class="o">{</span>
            <span class="nx">clearTimeout</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">_nDelayID</span><span class="o">);</span>
        <span class="o">}</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">_toggleContainer</span><span class="o">(</span><span class="kc">false</span><span class="o">);</span>
        <span class="k">return</span><span class="o">;</span>
    <span class="o">}</span>

    <span class="nx">sQuery</span> <span class="o">=</span> <span class="nb">encodeURIComponent</span><span class="o">(</span><span class="nx">sQuery</span><span class="o">);</span>
    <span class="k">this</span><span class="o">.</span><span class="nx">_nDelayID</span> <span class="o">=</span> <span class="o">-</span><span class="m">1</span><span class="o">;</span>    <span class="c">// Reset timeout ID because request has been made</span>
<span class="c"></span>    <span class="k">this</span><span class="o">.</span><span class="nx">dataRequestEvent</span><span class="o">.</span><span class="nx">fire</span><span class="o">(</span><span class="k">this</span><span class="o">,</span> <span class="nx">sQuery</span><span class="o">);</span>
    <span class="k">this</span><span class="o">.</span><span class="nx">dataSource</span><span class="o">.</span><span class="nx">getResults</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">_populateList</span><span class="o">,</span> <span class="nx">sQuery</span><span class="o">,</span> <span class="k">this</span><span class="o">);</span>
<span class="o">};</span>

<span class="c">/**</span>
<span class="c"> * Populates the array of &amp;lt;li&amp;gt; elements in the container with query</span>
<span class="c"> * results. This method is passed to YAHOO.widget.DataSource#getResults as a</span>
<span class="c"> * callback function so results from the DataSource instance are returned to the</span>
<span class="c"> * AutoComplete instance.</span>
<span class="c"> *</span>
<span class="c"> * @method _populateList</span>
<span class="c"> * @param sQuery {String} The query string.</span>
<span class="c"> * @param aResults {Object[]} An array of query result objects from the DataSource.</span>
<span class="c"> * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_populateList</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">sQuery</span><span class="o">,</span> <span class="nx">aResults</span><span class="o">,</span> <span class="nx">oSelf</span><span class="o">)</span> <span class="o">{</span>
    <span class="k">if</span><span class="o">(</span><span class="nx">aResults</span> <span class="o">===</span> <span class="kc">null</span><span class="o">)</span> <span class="o">{</span>
        <span class="nx">oSelf</span><span class="o">.</span><span class="nx">dataErrorEvent</span><span class="o">.</span><span class="nx">fire</span><span class="o">(</span><span class="nx">oSelf</span><span class="o">,</span> <span class="nx">sQuery</span><span class="o">);</span>
    <span class="o">}</span>
    <span class="k">if</span><span class="o">(!</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_bFocused</span> <span class="o">||</span> <span class="o">!</span><span class="nx">aResults</span><span class="o">)</span> <span class="o">{</span>
        <span class="k">return</span><span class="o">;</span>
    <span class="o">}</span>

    <span class="k">var</span> <span class="nx">isOpera</span> <span class="o">=</span> <span class="o">(</span><span class="nx">navigator</span><span class="o">.</span><span class="nx">userAgent</span><span class="o">.</span><span class="nx">toLowerCase</span><span class="o">().</span><span class="nx">indexOf</span><span class="o">(</span><span class="s2">&quot;opera&quot;</span><span class="o">)</span> <span class="o">!=</span> <span class="o">-</span><span class="m">1</span><span class="o">);</span>
    <span class="k">var</span> <span class="nx">contentStyle</span> <span class="o">=</span> <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">.</span><span class="nx">style</span><span class="o">;</span>
    <span class="nx">contentStyle</span><span class="o">.</span><span class="nx">width</span> <span class="o">=</span> <span class="o">(!</span><span class="nx">isOpera</span><span class="o">)</span> <span class="o">?</span> <span class="kc">null</span> <span class="o">:</span> <span class="s2">&quot;&quot;</span><span class="o">;</span>
    <span class="nx">contentStyle</span><span class="o">.</span><span class="nx">height</span> <span class="o">=</span> <span class="o">(!</span><span class="nx">isOpera</span><span class="o">)</span> <span class="o">?</span> <span class="kc">null</span> <span class="o">:</span> <span class="s2">&quot;&quot;</span><span class="o">;</span>

    <span class="k">var</span> <span class="nx">sCurQuery</span> <span class="o">=</span> <span class="nb">decodeURIComponent</span><span class="o">(</span><span class="nx">sQuery</span><span class="o">);</span>
    <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_sCurQuery</span> <span class="o">=</span> <span class="nx">sCurQuery</span><span class="o">;</span>
    <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_bItemSelected</span> <span class="o">=</span> <span class="kc">false</span><span class="o">;</span>

    <span class="k">if</span><span class="o">(</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_maxResultsDisplayed</span> <span class="o">!=</span> <span class="nx">oSelf</span><span class="o">.</span><span class="nx">maxResultsDisplayed</span><span class="o">)</span> <span class="o">{</span>
        <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_initList</span><span class="o">();</span>
    <span class="o">}</span>

    <span class="k">var</span> <span class="nx">nItems</span> <span class="o">=</span> <span class="nb">Math</span><span class="o">.</span><span class="nx">min</span><span class="o">(</span><span class="nx">aResults</span><span class="o">.</span><span class="nx">length</span><span class="o">,</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">maxResultsDisplayed</span><span class="o">);</span>
    <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_nDisplayedItems</span> <span class="o">=</span> <span class="nx">nItems</span><span class="o">;</span>
    <span class="k">if</span><span class="o">(</span><span class="nx">nItems</span> <span class="o">&gt;</span> <span class="m">0</span><span class="o">)</span> <span class="o">{</span>
        <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_initContainerHelpers</span><span class="o">();</span>
        <span class="k">var</span> <span class="nx">aItems</span> <span class="o">=</span> <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_aListItems</span><span class="o">;</span>

        <span class="c">// Fill items with data</span>
<span class="c"></span>        <span class="k">for</span><span class="o">(</span><span class="k">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="nx">nItems</span><span class="o">-</span><span class="m">1</span><span class="o">;</span> <span class="nx">i</span> <span class="o">&gt;=</span> <span class="m">0</span><span class="o">;</span> <span class="nx">i</span><span class="o">--)</span> <span class="o">{</span>
            <span class="k">var</span> <span class="nx">oItemi</span> <span class="o">=</span> <span class="nx">aItems</span><span class="o">[</span><span class="nx">i</span><span class="o">];</span>
            <span class="k">var</span> <span class="nx">oResultItemi</span> <span class="o">=</span> <span class="nx">aResults</span><span class="o">[</span><span class="nx">i</span><span class="o">];</span>
            <span class="nx">oItemi</span><span class="o">.</span><span class="nx">innerHTML</span> <span class="o">=</span> <span class="nx">oSelf</span><span class="o">.</span><span class="nx">formatResult</span><span class="o">(</span><span class="nx">oResultItemi</span><span class="o">,</span> <span class="nx">sCurQuery</span><span class="o">);</span>
            <span class="nx">oItemi</span><span class="o">.</span><span class="nx">style</span><span class="o">.</span><span class="nx">display</span> <span class="o">=</span> <span class="s2">&quot;list-item&quot;</span><span class="o">;</span>
            <span class="nx">oItemi</span><span class="o">.</span><span class="nx">_sResultKey</span> <span class="o">=</span> <span class="nx">oResultItemi</span><span class="o">[</span><span class="m">0</span><span class="o">];</span>
            <span class="nx">oItemi</span><span class="o">.</span><span class="nx">_oResultData</span> <span class="o">=</span> <span class="nx">oResultItemi</span><span class="o">;</span>

        <span class="o">}</span>

        <span class="c">// Empty out remaining items if any</span>
<span class="c"></span>        <span class="k">for</span><span class="o">(</span><span class="k">var</span> <span class="nx">j</span> <span class="o">=</span> <span class="nx">aItems</span><span class="o">.</span><span class="nx">length</span><span class="o">-</span><span class="m">1</span><span class="o">;</span> <span class="nx">j</span> <span class="o">&gt;=</span> <span class="nx">nItems</span> <span class="o">;</span> <span class="nx">j</span><span class="o">--)</span> <span class="o">{</span>
            <span class="k">var</span> <span class="nx">oItemj</span> <span class="o">=</span> <span class="nx">aItems</span><span class="o">[</span><span class="nx">j</span><span class="o">];</span>
            <span class="nx">oItemj</span><span class="o">.</span><span class="nx">innerHTML</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>
            <span class="nx">oItemj</span><span class="o">.</span><span class="nx">style</span><span class="o">.</span><span class="nx">display</span> <span class="o">=</span> <span class="s2">&quot;none&quot;</span><span class="o">;</span>
            <span class="nx">oItemj</span><span class="o">.</span><span class="nx">_sResultKey</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>
            <span class="nx">oItemj</span><span class="o">.</span><span class="nx">_oResultData</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>
        <span class="o">}</span>

        <span class="k">if</span><span class="o">(</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">autoHighlight</span><span class="o">)</span> <span class="o">{</span>
            <span class="c">// Go to the first item</span>
<span class="c"></span>            <span class="k">var</span> <span class="nx">oFirstItem</span> <span class="o">=</span> <span class="nx">aItems</span><span class="o">[</span><span class="m">0</span><span class="o">];</span>
            <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_toggleHighlight</span><span class="o">(</span><span class="nx">oFirstItem</span><span class="o">,</span><span class="s2">&quot;to&quot;</span><span class="o">);</span>
            <span class="nx">oSelf</span><span class="o">.</span><span class="nx">itemArrowToEvent</span><span class="o">.</span><span class="nx">fire</span><span class="o">(</span><span class="nx">oSelf</span><span class="o">,</span> <span class="nx">oFirstItem</span><span class="o">);</span>
            <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_typeAhead</span><span class="o">(</span><span class="nx">oFirstItem</span><span class="o">,</span><span class="nx">sQuery</span><span class="o">);</span>
        <span class="o">}</span>
        <span class="k">else</span> <span class="o">{</span>
            <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_oCurItem</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>
        <span class="o">}</span>

        <span class="c">// Expand the container</span>
<span class="c"></span>        <span class="k">var</span> <span class="nx">ok</span> <span class="o">=</span> <span class="nx">oSelf</span><span class="o">.</span><span class="nx">doBeforeExpandContainer</span><span class="o">(</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_oTextbox</span><span class="o">,</span> <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">,</span> <span class="nx">sQuery</span><span class="o">,</span> <span class="nx">aResults</span><span class="o">);</span>
        <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_toggleContainer</span><span class="o">(</span><span class="nx">ok</span><span class="o">);</span>
    <span class="o">}</span>
    <span class="k">else</span> <span class="o">{</span>
        <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_toggleContainer</span><span class="o">(</span><span class="kc">false</span><span class="o">);</span>
    <span class="o">}</span>
    <span class="nx">oSelf</span><span class="o">.</span><span class="nx">dataReturnEvent</span><span class="o">.</span><span class="nx">fire</span><span class="o">(</span><span class="nx">oSelf</span><span class="o">,</span> <span class="nx">sQuery</span><span class="o">,</span> <span class="nx">aResults</span><span class="o">);</span>
<span class="o">};</span>

<span class="c">/**</span>
<span class="c"> * When forceSelection is true and the user attempts</span>
<span class="c"> * leave the text input box without selecting an item from the query results,</span>
<span class="c"> * the user selection is cleared.</span>
<span class="c"> *</span>
<span class="c"> * @method _clearSelection</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_clearSelection</span> <span class="o">=</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
    <span class="k">var</span> <span class="nx">sValue</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_oTextbox</span><span class="o">.</span><span class="nx">value</span><span class="o">;</span>
    <span class="k">var</span> <span class="nx">sChar</span> <span class="o">=</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">delimChar</span><span class="o">)</span> <span class="o">?</span> <span class="k">this</span><span class="o">.</span><span class="nx">delimChar</span><span class="o">[</span><span class="m">0</span><span class="o">]</span> <span class="o">:</span> <span class="kc">null</span><span class="o">;</span>
    <span class="k">var</span> <span class="nx">nIndex</span> <span class="o">=</span> <span class="o">(</span><span class="nx">sChar</span><span class="o">)</span> <span class="o">?</span> <span class="nx">sValue</span><span class="o">.</span><span class="nx">lastIndexOf</span><span class="o">(</span><span class="nx">sChar</span><span class="o">,</span> <span class="nx">sValue</span><span class="o">.</span><span class="nx">length</span><span class="o">-</span><span class="m">2</span><span class="o">)</span> <span class="o">:</span> <span class="o">-</span><span class="m">1</span><span class="o">;</span>
    <span class="k">if</span><span class="o">(</span><span class="nx">nIndex</span> <span class="o">&gt;</span> <span class="o">-</span><span class="m">1</span><span class="o">)</span> <span class="o">{</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">_oTextbox</span><span class="o">.</span><span class="nx">value</span> <span class="o">=</span> <span class="nx">sValue</span><span class="o">.</span><span class="nx">substring</span><span class="o">(</span><span class="m">0</span><span class="o">,</span><span class="nx">nIndex</span><span class="o">);</span>
    <span class="o">}</span>
    <span class="k">else</span> <span class="o">{</span>
         <span class="k">this</span><span class="o">.</span><span class="nx">_oTextbox</span><span class="o">.</span><span class="nx">value</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span><span class="o">;</span>
    <span class="o">}</span>
    <span class="k">this</span><span class="o">.</span><span class="nx">_sSavedQuery</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_oTextbox</span><span class="o">.</span><span class="nx">value</span><span class="o">;</span>

    <span class="c">// Fire custom event</span>
<span class="c"></span>    <span class="k">this</span><span class="o">.</span><span class="nx">selectionEnforceEvent</span><span class="o">.</span><span class="nx">fire</span><span class="o">(</span><span class="k">this</span><span class="o">);</span>
<span class="o">};</span>

<span class="c">/**</span>
<span class="c"> * Whether or not user-typed value in the text input box matches any of the</span>
<span class="c"> * query results.</span>
<span class="c"> *</span>
<span class="c"> * @method _textMatchesOption</span>
<span class="c"> * @return {Boolean} True if user-input text matches a result, false otherwise.</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_textMatchesOption</span> <span class="o">=</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
    <span class="k">var</span> <span class="nx">foundMatch</span> <span class="o">=</span> <span class="kc">false</span><span class="o">;</span>

    <span class="k">for</span><span class="o">(</span><span class="k">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_nDisplayedItems</span><span class="o">-</span><span class="m">1</span><span class="o">;</span> <span class="nx">i</span> <span class="o">&gt;=</span> <span class="m">0</span> <span class="o">;</span> <span class="nx">i</span><span class="o">--)</span> <span class="o">{</span>
        <span class="k">var</span> <span class="nx">oItem</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_aListItems</span><span class="o">[</span><span class="nx">i</span><span class="o">];</span>
        <span class="k">var</span> <span class="nx">sMatch</span> <span class="o">=</span> <span class="nx">oItem</span><span class="o">.</span><span class="nx">_sResultKey</span><span class="o">.</span><span class="nx">toLowerCase</span><span class="o">();</span>
        <span class="k">if</span><span class="o">(</span><span class="nx">sMatch</span> <span class="o">==</span> <span class="k">this</span><span class="o">.</span><span class="nx">_sCurQuery</span><span class="o">.</span><span class="nx">toLowerCase</span><span class="o">())</span> <span class="o">{</span>
            <span class="nx">foundMatch</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>
            <span class="k">break</span><span class="o">;</span>
        <span class="o">}</span>
    <span class="o">}</span>
    <span class="k">return</span><span class="o">(</span><span class="nx">foundMatch</span><span class="o">);</span>
<span class="o">};</span>

<span class="c">/**</span>
<span class="c"> * Updates in the text input box with the first query result as the user types,</span>
<span class="c"> * selecting the substring that the user has not typed.</span>
<span class="c"> *</span>
<span class="c"> * @method _typeAhead</span>
<span class="c"> * @param oItem {HTMLElement} The &amp;lt;li&amp;gt; element item whose data populates the input field.</span>
<span class="c"> * @param sQuery {String} Query string.</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_typeAhead</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">oItem</span><span class="o">,</span> <span class="nx">sQuery</span><span class="o">)</span> <span class="o">{</span>
    <span class="c">// Don&#39;t update if turned off</span>
<span class="c"></span>    <span class="k">if</span><span class="o">(!</span><span class="k">this</span><span class="o">.</span><span class="nx">typeAhead</span> <span class="o">||</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">_nKeyCode</span> <span class="o">==</span> <span class="m">8</span><span class="o">))</span> <span class="o">{</span>
        <span class="k">return</span><span class="o">;</span>
    <span class="o">}</span>

    <span class="k">var</span> <span class="nx">oTextbox</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_oTextbox</span><span class="o">;</span>
    <span class="k">var</span> <span class="nx">sValue</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_oTextbox</span><span class="o">.</span><span class="nx">value</span><span class="o">;</span> <span class="c">// any saved queries plus what user has typed</span>
<span class="c"></span>
    <span class="c">// Don&#39;t update with type-ahead if text selection is not supported</span>
<span class="c"></span>    <span class="k">if</span><span class="o">(!</span><span class="nx">oTextbox</span><span class="o">.</span><span class="nx">setSelectionRange</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="nx">oTextbox</span><span class="o">.</span><span class="nx">createTextRange</span><span class="o">)</span> <span class="o">{</span>
        <span class="k">return</span><span class="o">;</span>
    <span class="o">}</span>

    <span class="c">// Select the portion of text that the user has not typed</span>
<span class="c"></span>    <span class="k">var</span> <span class="nx">nStart</span> <span class="o">=</span> <span class="nx">sValue</span><span class="o">.</span><span class="nx">length</span><span class="o">;</span>
    <span class="k">this</span><span class="o">.</span><span class="nx">_updateValue</span><span class="o">(</span><span class="nx">oItem</span><span class="o">);</span>
    <span class="k">var</span> <span class="nx">nEnd</span> <span class="o">=</span> <span class="nx">oTextbox</span><span class="o">.</span><span class="nx">value</span><span class="o">.</span><span class="nx">length</span><span class="o">;</span>
    <span class="k">this</span><span class="o">.</span><span class="nx">_selectText</span><span class="o">(</span><span class="nx">oTextbox</span><span class="o">,</span><span class="nx">nStart</span><span class="o">,</span><span class="nx">nEnd</span><span class="o">);</span>
    <span class="k">var</span> <span class="nx">sPrefill</span> <span class="o">=</span> <span class="nx">oTextbox</span><span class="o">.</span><span class="nx">value</span><span class="o">.</span><span class="nx">substr</span><span class="o">(</span><span class="nx">nStart</span><span class="o">,</span><span class="nx">nEnd</span><span class="o">);</span>
    <span class="k">this</span><span class="o">.</span><span class="nx">typeAheadEvent</span><span class="o">.</span><span class="nx">fire</span><span class="o">(</span><span class="k">this</span><span class="o">,</span><span class="nx">sQuery</span><span class="o">,</span><span class="nx">sPrefill</span><span class="o">);</span>
<span class="o">};</span>

<span class="c">/**</span>
<span class="c"> * Selects text in the input field.</span>
<span class="c"> *</span>
<span class="c"> * @method _selectText</span>
<span class="c"> * @param oTextbox {HTMLElement} Text input box element in which to select text.</span>
<span class="c"> * @param nStart {Number} Starting index of text string to select.</span>
<span class="c"> * @param nEnd {Number} Ending index of text selection.</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_selectText</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">oTextbox</span><span class="o">,</span> <span class="nx">nStart</span><span class="o">,</span> <span class="nx">nEnd</span><span class="o">)</span> <span class="o">{</span>
    <span class="k">if</span><span class="o">(</span><span class="nx">oTextbox</span><span class="o">.</span><span class="nx">setSelectionRange</span><span class="o">)</span> <span class="o">{</span> <span class="c">// For Mozilla</span>
<span class="c"></span>        <span class="nx">oTextbox</span><span class="o">.</span><span class="nx">setSelectionRange</span><span class="o">(</span><span class="nx">nStart</span><span class="o">,</span><span class="nx">nEnd</span><span class="o">);</span>
    <span class="o">}</span>
    <span class="k">else</span> <span class="k">if</span><span class="o">(</span><span class="nx">oTextbox</span><span class="o">.</span><span class="nx">createTextRange</span><span class="o">)</span> <span class="o">{</span> <span class="c">// For IE</span>
<span class="c"></span>        <span class="k">var</span> <span class="nx">oTextRange</span> <span class="o">=</span> <span class="nx">oTextbox</span><span class="o">.</span><span class="nx">createTextRange</span><span class="o">();</span>
        <span class="nx">oTextRange</span><span class="o">.</span><span class="nx">moveStart</span><span class="o">(</span><span class="s2">&quot;character&quot;</span><span class="o">,</span> <span class="nx">nStart</span><span class="o">);</span>
        <span class="nx">oTextRange</span><span class="o">.</span><span class="nx">moveEnd</span><span class="o">(</span><span class="s2">&quot;character&quot;</span><span class="o">,</span> <span class="nx">nEnd</span><span class="o">-</span><span class="nx">oTextbox</span><span class="o">.</span><span class="nx">value</span><span class="o">.</span><span class="nx">length</span><span class="o">);</span>
        <span class="nx">oTextRange</span><span class="o">.</span><span class="nx">select</span><span class="o">();</span>
    <span class="o">}</span>
    <span class="k">else</span> <span class="o">{</span>
        <span class="nx">oTextbox</span><span class="o">.</span><span class="nx">select</span><span class="o">();</span>
    <span class="o">}</span>
<span class="o">};</span>

<span class="c">/**</span>
<span class="c"> * Syncs results container with its helpers.</span>
<span class="c"> *</span>
<span class="c"> * @method _toggleContainerHelpers</span>
<span class="c"> * @param bShow {Boolean} True if container is expanded, false if collapsed</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_toggleContainerHelpers</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">bShow</span><span class="o">)</span> <span class="o">{</span>
    <span class="k">var</span> <span class="nx">bFireEvent</span> <span class="o">=</span> <span class="kc">false</span><span class="o">;</span>
    <span class="k">var</span> <span class="nx">width</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">.</span><span class="nx">offsetWidth</span> <span class="o">+</span> <span class="s2">&quot;px&quot;</span><span class="o">;</span>
    <span class="k">var</span> <span class="nx">height</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">.</span><span class="nx">offsetHeight</span> <span class="o">+</span> <span class="s2">&quot;px&quot;</span><span class="o">;</span>

    <span class="k">if</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">useIFrame</span> <span class="o">&amp;&amp;</span> <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oIFrame</span><span class="o">)</span> <span class="o">{</span>
        <span class="nx">bFireEvent</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>
        <span class="k">if</span><span class="o">(</span><span class="nx">bShow</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oIFrame</span><span class="o">.</span><span class="nx">style</span><span class="o">.</span><span class="nx">width</span> <span class="o">=</span> <span class="nx">width</span><span class="o">;</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oIFrame</span><span class="o">.</span><span class="nx">style</span><span class="o">.</span><span class="nx">height</span> <span class="o">=</span> <span class="nx">height</span><span class="o">;</span>
        <span class="o">}</span>
        <span class="k">else</span> <span class="o">{</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oIFrame</span><span class="o">.</span><span class="nx">style</span><span class="o">.</span><span class="nx">width</span> <span class="o">=</span> <span class="m">0</span><span class="o">;</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oIFrame</span><span class="o">.</span><span class="nx">style</span><span class="o">.</span><span class="nx">height</span> <span class="o">=</span> <span class="m">0</span><span class="o">;</span>
        <span class="o">}</span>
    <span class="o">}</span>
    <span class="k">if</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">useShadow</span> <span class="o">&amp;&amp;</span> <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oShadow</span><span class="o">)</span> <span class="o">{</span>
        <span class="nx">bFireEvent</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>
        <span class="k">if</span><span class="o">(</span><span class="nx">bShow</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oShadow</span><span class="o">.</span><span class="nx">style</span><span class="o">.</span><span class="nx">width</span> <span class="o">=</span> <span class="nx">width</span><span class="o">;</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oShadow</span><span class="o">.</span><span class="nx">style</span><span class="o">.</span><span class="nx">height</span> <span class="o">=</span> <span class="nx">height</span><span class="o">;</span>
        <span class="o">}</span>
        <span class="k">else</span> <span class="o">{</span>
           <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oShadow</span><span class="o">.</span><span class="nx">style</span><span class="o">.</span><span class="nx">width</span> <span class="o">=</span> <span class="m">0</span><span class="o">;</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oShadow</span><span class="o">.</span><span class="nx">style</span><span class="o">.</span><span class="nx">height</span> <span class="o">=</span> <span class="m">0</span><span class="o">;</span>
        <span class="o">}</span>
    <span class="o">}</span>
<span class="o">};</span>

<span class="c">/**</span>
<span class="c"> * Animates expansion or collapse of the container.</span>
<span class="c"> *</span>
<span class="c"> * @method _toggleContainer</span>
<span class="c"> * @param bShow {Boolean} True if container should be expanded, false if container should be collapsed</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_toggleContainer</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">bShow</span><span class="o">)</span> <span class="o">{</span>
    <span class="k">var</span> <span class="nx">oContainer</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">;</span>

    <span class="c">// Implementer has container always open so don&#39;t mess with it</span>
<span class="c"></span>    <span class="k">if</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">alwaysShowContainer</span> <span class="o">&amp;&amp;</span> <span class="k">this</span><span class="o">.</span><span class="nx">_bContainerOpen</span><span class="o">)</span> <span class="o">{</span>
        <span class="k">return</span><span class="o">;</span>
    <span class="o">}</span>
    
    <span class="c">// Clear contents of container</span>
<span class="c"></span>    <span class="k">if</span><span class="o">(!</span><span class="nx">bShow</span><span class="o">)</span> <span class="o">{</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">.</span><span class="nx">scrollTop</span> <span class="o">=</span> <span class="m">0</span><span class="o">;</span>
        <span class="k">var</span> <span class="nx">aItems</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_aListItems</span><span class="o">;</span>

        <span class="k">if</span><span class="o">(</span><span class="nx">aItems</span> <span class="o">&amp;&amp;</span> <span class="o">(</span><span class="nx">aItems</span><span class="o">.</span><span class="nx">length</span> <span class="o">&gt;</span> <span class="m">0</span><span class="o">))</span> <span class="o">{</span>
            <span class="k">for</span><span class="o">(</span><span class="k">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="nx">aItems</span><span class="o">.</span><span class="nx">length</span><span class="o">-</span><span class="m">1</span><span class="o">;</span> <span class="nx">i</span> <span class="o">&gt;=</span> <span class="m">0</span> <span class="o">;</span> <span class="nx">i</span><span class="o">--)</span> <span class="o">{</span>
                <span class="nx">aItems</span><span class="o">[</span><span class="nx">i</span><span class="o">].</span><span class="nx">style</span><span class="o">.</span><span class="nx">display</span> <span class="o">=</span> <span class="s2">&quot;none&quot;</span><span class="o">;</span>
            <span class="o">}</span>
        <span class="o">}</span>

        <span class="k">if</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">_oCurItem</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">_toggleHighlight</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">_oCurItem</span><span class="o">,</span><span class="s2">&quot;from&quot;</span><span class="o">);</span>
        <span class="o">}</span>

        <span class="k">this</span><span class="o">.</span><span class="nx">_oCurItem</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">_nDisplayedItems</span> <span class="o">=</span> <span class="m">0</span><span class="o">;</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">_sCurQuery</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>
    <span class="o">}</span>

    <span class="c">// Container is already closed</span>
<span class="c"></span>    <span class="k">if</span><span class="o">(!</span><span class="nx">bShow</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="k">this</span><span class="o">.</span><span class="nx">_bContainerOpen</span><span class="o">)</span> <span class="o">{</span>
        <span class="nx">oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">.</span><span class="nx">style</span><span class="o">.</span><span class="nx">display</span> <span class="o">=</span> <span class="s2">&quot;none&quot;</span><span class="o">;</span>
        <span class="k">return</span><span class="o">;</span>
    <span class="o">}</span>

    <span class="c">// If animation is enabled...</span>
<span class="c"></span>    <span class="k">var</span> <span class="nx">oAnim</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_oAnim</span><span class="o">;</span>
    <span class="k">if</span><span class="o">(</span><span class="nx">oAnim</span> <span class="o">&amp;&amp;</span> <span class="nx">oAnim</span><span class="o">.</span><span class="nx">getEl</span><span class="o">()</span> <span class="o">&amp;&amp;</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">animHoriz</span> <span class="o">||</span> <span class="k">this</span><span class="o">.</span><span class="nx">animVert</span><span class="o">))</span> <span class="o">{</span>
        <span class="c">// If helpers need to be collapsed, do it right away...</span>
<span class="c"></span>        <span class="c">// but if helpers need to be expanded, wait until after the container expands</span>
<span class="c"></span>        <span class="k">if</span><span class="o">(!</span><span class="nx">bShow</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">_toggleContainerHelpers</span><span class="o">(</span><span class="nx">bShow</span><span class="o">);</span>
        <span class="o">}</span>

        <span class="k">if</span><span class="o">(</span><span class="nx">oAnim</span><span class="o">.</span><span class="nx">isAnimated</span><span class="o">())</span> <span class="o">{</span>
            <span class="nx">oAnim</span><span class="o">.</span><span class="nx">stop</span><span class="o">();</span>
        <span class="o">}</span>

        <span class="c">// Clone container to grab current size offscreen</span>
<span class="c"></span>        <span class="k">var</span> <span class="nx">oClone</span> <span class="o">=</span> <span class="nx">oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">.</span><span class="nx">cloneNode</span><span class="o">(</span><span class="kc">true</span><span class="o">);</span>
        <span class="nx">oContainer</span><span class="o">.</span><span class="nx">appendChild</span><span class="o">(</span><span class="nx">oClone</span><span class="o">);</span>
        <span class="nx">oClone</span><span class="o">.</span><span class="nx">style</span><span class="o">.</span><span class="nx">top</span> <span class="o">=</span> <span class="s2">&quot;-9000px&quot;</span><span class="o">;</span>
        <span class="nx">oClone</span><span class="o">.</span><span class="nx">style</span><span class="o">.</span><span class="nx">display</span> <span class="o">=</span> <span class="s2">&quot;block&quot;</span><span class="o">;</span>

        <span class="c">// Current size of the container is the EXPANDED size</span>
<span class="c"></span>        <span class="k">var</span> <span class="nx">wExp</span> <span class="o">=</span> <span class="nx">oClone</span><span class="o">.</span><span class="nx">offsetWidth</span><span class="o">;</span>
        <span class="k">var</span> <span class="nx">hExp</span> <span class="o">=</span> <span class="nx">oClone</span><span class="o">.</span><span class="nx">offsetHeight</span><span class="o">;</span>

        <span class="c">// Calculate COLLAPSED sizes based on horiz and vert anim</span>
<span class="c"></span>        <span class="k">var</span> <span class="nx">wColl</span> <span class="o">=</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">animHoriz</span><span class="o">)</span> <span class="o">?</span> <span class="m">0</span> <span class="o">:</span> <span class="nx">wExp</span><span class="o">;</span>
        <span class="k">var</span> <span class="nx">hColl</span> <span class="o">=</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">animVert</span><span class="o">)</span> <span class="o">?</span> <span class="m">0</span> <span class="o">:</span> <span class="nx">hExp</span><span class="o">;</span>

        <span class="c">// Set animation sizes</span>
<span class="c"></span>        <span class="nx">oAnim</span><span class="o">.</span><span class="nx">attributes</span> <span class="o">=</span> <span class="o">(</span><span class="nx">bShow</span><span class="o">)</span> <span class="o">?</span>
            <span class="o">{</span><span class="nx">width</span><span class="o">:</span> <span class="o">{</span> <span class="nx">to</span><span class="o">:</span> <span class="nx">wExp</span> <span class="o">},</span> <span class="nx">height</span><span class="o">:</span> <span class="o">{</span> <span class="nx">to</span><span class="o">:</span> <span class="nx">hExp</span> <span class="o">}}</span> <span class="o">:</span>
            <span class="o">{</span><span class="nx">width</span><span class="o">:</span> <span class="o">{</span> <span class="nx">to</span><span class="o">:</span> <span class="nx">wColl</span><span class="o">},</span> <span class="nx">height</span><span class="o">:</span> <span class="o">{</span> <span class="nx">to</span><span class="o">:</span> <span class="nx">hColl</span> <span class="o">}};</span>

        <span class="c">// If opening anew, set to a collapsed size...</span>
<span class="c"></span>        <span class="k">if</span><span class="o">(</span><span class="nx">bShow</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="k">this</span><span class="o">.</span><span class="nx">_bContainerOpen</span><span class="o">)</span> <span class="o">{</span>
            <span class="nx">oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">.</span><span class="nx">style</span><span class="o">.</span><span class="nx">width</span> <span class="o">=</span> <span class="nx">wColl</span><span class="o">+</span><span class="s2">&quot;px&quot;</span><span class="o">;</span>
            <span class="nx">oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">.</span><span class="nx">style</span><span class="o">.</span><span class="nx">height</span> <span class="o">=</span> <span class="nx">hColl</span><span class="o">+</span><span class="s2">&quot;px&quot;</span><span class="o">;</span>
        <span class="o">}</span>
        <span class="c">// Else, set it to its last known size.</span>
<span class="c"></span>        <span class="k">else</span> <span class="o">{</span>
            <span class="nx">oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">.</span><span class="nx">style</span><span class="o">.</span><span class="nx">width</span> <span class="o">=</span> <span class="nx">wExp</span><span class="o">+</span><span class="s2">&quot;px&quot;</span><span class="o">;</span>
            <span class="nx">oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">.</span><span class="nx">style</span><span class="o">.</span><span class="nx">height</span> <span class="o">=</span> <span class="nx">hExp</span><span class="o">+</span><span class="s2">&quot;px&quot;</span><span class="o">;</span>
        <span class="o">}</span>

        <span class="nx">oContainer</span><span class="o">.</span><span class="nx">removeChild</span><span class="o">(</span><span class="nx">oClone</span><span class="o">);</span>
        <span class="nx">oClone</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>

    	<span class="k">var</span> <span class="nx">oSelf</span> <span class="o">=</span> <span class="k">this</span><span class="o">;</span>
    	<span class="k">var</span> <span class="nx">onAnimComplete</span> <span class="o">=</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
            <span class="c">// Finish the collapse</span>
<span class="c"></span>    		<span class="nx">oAnim</span><span class="o">.</span><span class="nx">onComplete</span><span class="o">.</span><span class="nx">unsubscribeAll</span><span class="o">();</span>

            <span class="k">if</span><span class="o">(</span><span class="nx">bShow</span><span class="o">)</span> <span class="o">{</span>
                <span class="nx">oSelf</span><span class="o">.</span><span class="nx">containerExpandEvent</span><span class="o">.</span><span class="nx">fire</span><span class="o">(</span><span class="nx">oSelf</span><span class="o">);</span>
            <span class="o">}</span>
            <span class="k">else</span> <span class="o">{</span>
                <span class="nx">oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">.</span><span class="nx">style</span><span class="o">.</span><span class="nx">display</span> <span class="o">=</span> <span class="s2">&quot;none&quot;</span><span class="o">;</span>
                <span class="nx">oSelf</span><span class="o">.</span><span class="nx">containerCollapseEvent</span><span class="o">.</span><span class="nx">fire</span><span class="o">(</span><span class="nx">oSelf</span><span class="o">);</span>
            <span class="o">}</span>
            <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_toggleContainerHelpers</span><span class="o">(</span><span class="nx">bShow</span><span class="o">);</span>
     	<span class="o">};</span>

        <span class="c">// Display container and animate it</span>
<span class="c"></span>        <span class="nx">oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">.</span><span class="nx">style</span><span class="o">.</span><span class="nx">display</span> <span class="o">=</span> <span class="s2">&quot;block&quot;</span><span class="o">;</span>
        <span class="nx">oAnim</span><span class="o">.</span><span class="nx">onComplete</span><span class="o">.</span><span class="nx">subscribe</span><span class="o">(</span><span class="nx">onAnimComplete</span><span class="o">);</span>
        <span class="nx">oAnim</span><span class="o">.</span><span class="nx">animate</span><span class="o">();</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">_bContainerOpen</span> <span class="o">=</span> <span class="nx">bShow</span><span class="o">;</span>
    <span class="o">}</span>
    <span class="c">// Else don&#39;t animate, just show or hide</span>
<span class="c"></span>    <span class="k">else</span> <span class="o">{</span>
        <span class="k">if</span><span class="o">(</span><span class="nx">bShow</span><span class="o">)</span> <span class="o">{</span>
            <span class="nx">oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">.</span><span class="nx">style</span><span class="o">.</span><span class="nx">display</span> <span class="o">=</span> <span class="s2">&quot;block&quot;</span><span class="o">;</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">containerExpandEvent</span><span class="o">.</span><span class="nx">fire</span><span class="o">(</span><span class="k">this</span><span class="o">);</span>
        <span class="o">}</span>
        <span class="k">else</span> <span class="o">{</span>
            <span class="nx">oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">.</span><span class="nx">style</span><span class="o">.</span><span class="nx">display</span> <span class="o">=</span> <span class="s2">&quot;none&quot;</span><span class="o">;</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">containerCollapseEvent</span><span class="o">.</span><span class="nx">fire</span><span class="o">(</span><span class="k">this</span><span class="o">);</span>
        <span class="o">}</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">_toggleContainerHelpers</span><span class="o">(</span><span class="nx">bShow</span><span class="o">);</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">_bContainerOpen</span> <span class="o">=</span> <span class="nx">bShow</span><span class="o">;</span>
   <span class="o">}</span>

<span class="o">};</span>

<span class="c">/**</span>
<span class="c"> * Toggles the highlight on or off for an item in the container, and also cleans</span>
<span class="c"> * up highlighting of any previous item.</span>
<span class="c"> *</span>
<span class="c"> * @method _toggleHighlight</span>
<span class="c"> * @param oNewItem {HTMLElement} The &amp;lt;li&amp;gt; element item to receive highlight behavior.</span>
<span class="c"> * @param sType {String} Type &quot;mouseover&quot; will toggle highlight on, and &quot;mouseout&quot; will toggle highlight off.</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_toggleHighlight</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">oNewItem</span><span class="o">,</span> <span class="nx">sType</span><span class="o">)</span> <span class="o">{</span>
    <span class="k">var</span> <span class="nx">sHighlight</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">highlightClassName</span><span class="o">;</span>
    <span class="k">if</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">_oCurItem</span><span class="o">)</span> <span class="o">{</span>
        <span class="c">// Remove highlight from old item</span>
<span class="c"></span>        <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">Dom</span><span class="o">.</span><span class="nx">removeClass</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">_oCurItem</span><span class="o">,</span> <span class="nx">sHighlight</span><span class="o">);</span>
    <span class="o">}</span>

    <span class="k">if</span><span class="o">((</span><span class="nx">sType</span> <span class="o">==</span> <span class="s2">&quot;to&quot;</span><span class="o">)</span> <span class="o">&amp;&amp;</span> <span class="nx">sHighlight</span><span class="o">)</span> <span class="o">{</span>
        <span class="c">// Apply highlight to new item</span>
<span class="c"></span>        <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">Dom</span><span class="o">.</span><span class="nx">addClass</span><span class="o">(</span><span class="nx">oNewItem</span><span class="o">,</span> <span class="nx">sHighlight</span><span class="o">);</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">_oCurItem</span> <span class="o">=</span> <span class="nx">oNewItem</span><span class="o">;</span>
    <span class="o">}</span>
<span class="o">};</span>

<span class="c">/**</span>
<span class="c"> * Toggles the pre-highlight on or off for an item in the container.</span>
<span class="c"> *</span>
<span class="c"> * @method _togglePrehighlight</span>
<span class="c"> * @param oNewItem {HTMLElement} The &amp;lt;li&amp;gt; element item to receive highlight behavior.</span>
<span class="c"> * @param sType {String} Type &quot;mouseover&quot; will toggle highlight on, and &quot;mouseout&quot; will toggle highlight off.</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_togglePrehighlight</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">oNewItem</span><span class="o">,</span> <span class="nx">sType</span><span class="o">)</span> <span class="o">{</span>
    <span class="k">if</span><span class="o">(</span><span class="nx">oNewItem</span> <span class="o">==</span> <span class="k">this</span><span class="o">.</span><span class="nx">_oCurItem</span><span class="o">)</span> <span class="o">{</span>
        <span class="k">return</span><span class="o">;</span>
    <span class="o">}</span>

    <span class="k">var</span> <span class="nx">sPrehighlight</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">prehighlightClassName</span><span class="o">;</span>
    <span class="k">if</span><span class="o">((</span><span class="nx">sType</span> <span class="o">==</span> <span class="s2">&quot;mouseover&quot;</span><span class="o">)</span> <span class="o">&amp;&amp;</span> <span class="nx">sPrehighlight</span><span class="o">)</span> <span class="o">{</span>
        <span class="c">// Apply prehighlight to new item</span>
<span class="c"></span>        <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">Dom</span><span class="o">.</span><span class="nx">addClass</span><span class="o">(</span><span class="nx">oNewItem</span><span class="o">,</span> <span class="nx">sPrehighlight</span><span class="o">);</span>
    <span class="o">}</span>
    <span class="k">else</span> <span class="o">{</span>
        <span class="c">// Remove prehighlight from old item</span>
<span class="c"></span>        <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">Dom</span><span class="o">.</span><span class="nx">removeClass</span><span class="o">(</span><span class="nx">oNewItem</span><span class="o">,</span> <span class="nx">sPrehighlight</span><span class="o">);</span>
    <span class="o">}</span>
<span class="o">};</span>

<span class="c">/**</span>
<span class="c"> * Updates the text input box value with selected query result. If a delimiter</span>
<span class="c"> * has been defined, then the value gets appended with the delimiter.</span>
<span class="c"> *</span>
<span class="c"> * @method _updateValue</span>
<span class="c"> * @param oItem {HTMLElement} The &amp;lt;li&amp;gt; element item with which to update the value.</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_updateValue</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">oItem</span><span class="o">)</span> <span class="o">{</span>
    <span class="k">var</span> <span class="nx">oTextbox</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_oTextbox</span><span class="o">;</span>
    <span class="k">var</span> <span class="nx">sDelimChar</span> <span class="o">=</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">delimChar</span><span class="o">)</span> <span class="o">?</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">delimChar</span><span class="o">[</span><span class="m">0</span><span class="o">]</span> <span class="o">||</span> <span class="k">this</span><span class="o">.</span><span class="nx">delimChar</span><span class="o">)</span> <span class="o">:</span> <span class="kc">null</span><span class="o">;</span>
    <span class="k">var</span> <span class="nx">sSavedQuery</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_sSavedQuery</span><span class="o">;</span>
    <span class="k">var</span> <span class="nx">sResultKey</span> <span class="o">=</span> <span class="nx">oItem</span><span class="o">.</span><span class="nx">_sResultKey</span><span class="o">;</span>
    <span class="nx">oTextbox</span><span class="o">.</span><span class="nx">focus</span><span class="o">();</span>

    <span class="c">// First clear text field</span>
<span class="c"></span>    <span class="nx">oTextbox</span><span class="o">.</span><span class="nx">value</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span><span class="o">;</span>
    <span class="c">// Grab data to put into text field</span>
<span class="c"></span>    <span class="k">if</span><span class="o">(</span><span class="nx">sDelimChar</span><span class="o">)</span> <span class="o">{</span>
        <span class="k">if</span><span class="o">(</span><span class="nx">sSavedQuery</span><span class="o">)</span> <span class="o">{</span>
            <span class="nx">oTextbox</span><span class="o">.</span><span class="nx">value</span> <span class="o">=</span> <span class="nx">sSavedQuery</span><span class="o">;</span>
        <span class="o">}</span>
        <span class="nx">oTextbox</span><span class="o">.</span><span class="nx">value</span> <span class="o">+=</span> <span class="nx">sResultKey</span> <span class="o">+</span> <span class="nx">sDelimChar</span><span class="o">;</span>
        <span class="k">if</span><span class="o">(</span><span class="nx">sDelimChar</span> <span class="o">!=</span> <span class="s2">&quot; &quot;</span><span class="o">)</span> <span class="o">{</span>
            <span class="nx">oTextbox</span><span class="o">.</span><span class="nx">value</span> <span class="o">+=</span> <span class="s2">&quot; &quot;</span><span class="o">;</span>
        <span class="o">}</span>
    <span class="o">}</span>
    <span class="k">else</span> <span class="o">{</span> <span class="nx">oTextbox</span><span class="o">.</span><span class="nx">value</span> <span class="o">=</span> <span class="nx">sResultKey</span><span class="o">;</span> <span class="o">}</span>

    <span class="c">// scroll to bottom of textarea if necessary</span>
<span class="c"></span>    <span class="k">if</span><span class="o">(</span><span class="nx">oTextbox</span><span class="o">.</span><span class="nx">type</span> <span class="o">==</span> <span class="s2">&quot;textarea&quot;</span><span class="o">)</span> <span class="o">{</span>
        <span class="nx">oTextbox</span><span class="o">.</span><span class="nx">scrollTop</span> <span class="o">=</span> <span class="nx">oTextbox</span><span class="o">.</span><span class="nx">scrollHeight</span><span class="o">;</span>
    <span class="o">}</span>

    <span class="c">// move cursor to end</span>
<span class="c"></span>    <span class="k">var</span> <span class="nx">end</span> <span class="o">=</span> <span class="nx">oTextbox</span><span class="o">.</span><span class="nx">value</span><span class="o">.</span><span class="nx">length</span><span class="o">;</span>
    <span class="k">this</span><span class="o">.</span><span class="nx">_selectText</span><span class="o">(</span><span class="nx">oTextbox</span><span class="o">,</span><span class="nx">end</span><span class="o">,</span><span class="nx">end</span><span class="o">);</span>

    <span class="k">this</span><span class="o">.</span><span class="nx">_oCurItem</span> <span class="o">=</span> <span class="nx">oItem</span><span class="o">;</span>
<span class="o">};</span>

<span class="c">/**</span>
<span class="c"> * Selects a result item from the container</span>
<span class="c"> *</span>
<span class="c"> * @method _selectItem</span>
<span class="c"> * @param oItem {HTMLElement} The selected &amp;lt;li&amp;gt; element item.</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_selectItem</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">oItem</span><span class="o">)</span> <span class="o">{</span>
    <span class="k">this</span><span class="o">.</span><span class="nx">_bItemSelected</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>
    <span class="k">this</span><span class="o">.</span><span class="nx">_updateValue</span><span class="o">(</span><span class="nx">oItem</span><span class="o">);</span>
    <span class="k">this</span><span class="o">.</span><span class="nx">_cancelIntervalDetection</span><span class="o">(</span><span class="k">this</span><span class="o">);</span>
    <span class="k">this</span><span class="o">.</span><span class="nx">itemSelectEvent</span><span class="o">.</span><span class="nx">fire</span><span class="o">(</span><span class="k">this</span><span class="o">,</span> <span class="nx">oItem</span><span class="o">,</span> <span class="nx">oItem</span><span class="o">.</span><span class="nx">_oResultData</span><span class="o">);</span>
    <span class="k">this</span><span class="o">.</span><span class="nx">_toggleContainer</span><span class="o">(</span><span class="kc">false</span><span class="o">);</span>
<span class="o">};</span>

<span class="c">/**</span>
<span class="c"> * For values updated by type-ahead, the right arrow key jumps to the end</span>
<span class="c"> * of the textbox, otherwise the container is closed.</span>
<span class="c"> *</span>
<span class="c"> * @method _jumpSelection</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_jumpSelection</span> <span class="o">=</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
    <span class="k">if</span><span class="o">(!</span><span class="k">this</span><span class="o">.</span><span class="nx">typeAhead</span><span class="o">)</span> <span class="o">{</span>
        <span class="k">return</span><span class="o">;</span>
    <span class="o">}</span>
    <span class="k">else</span> <span class="o">{</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">_toggleContainer</span><span class="o">(</span><span class="kc">false</span><span class="o">);</span>
    <span class="o">}</span>
<span class="o">};</span>

<span class="c">/**</span>
<span class="c"> * Triggered by up and down arrow keys, changes the current highlighted</span>
<span class="c"> * &amp;lt;li&amp;gt; element item. Scrolls container if necessary.</span>
<span class="c"> *</span>
<span class="c"> * @method _moveSelection</span>
<span class="c"> * @param nKeyCode {Number} Code of key pressed.</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_moveSelection</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">nKeyCode</span><span class="o">)</span> <span class="o">{</span>
    <span class="k">if</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">_bContainerOpen</span><span class="o">)</span> <span class="o">{</span>
        <span class="c">// Determine current item&#39;s id number</span>
<span class="c"></span>        <span class="k">var</span> <span class="nx">oCurItem</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_oCurItem</span><span class="o">;</span>
        <span class="k">var</span> <span class="nx">nCurItemIndex</span> <span class="o">=</span> <span class="o">-</span><span class="m">1</span><span class="o">;</span>

        <span class="k">if</span><span class="o">(</span><span class="nx">oCurItem</span><span class="o">)</span> <span class="o">{</span>
            <span class="nx">nCurItemIndex</span> <span class="o">=</span> <span class="nx">oCurItem</span><span class="o">.</span><span class="nx">_nItemIndex</span><span class="o">;</span>
        <span class="o">}</span>

        <span class="k">var</span> <span class="nx">nNewItemIndex</span> <span class="o">=</span> <span class="o">(</span><span class="nx">nKeyCode</span> <span class="o">==</span> <span class="m">40</span><span class="o">)</span> <span class="o">?</span>
                <span class="o">(</span><span class="nx">nCurItemIndex</span> <span class="o">+</span> <span class="m">1</span><span class="o">)</span> <span class="o">:</span> <span class="o">(</span><span class="nx">nCurItemIndex</span> <span class="o">-</span> <span class="m">1</span><span class="o">);</span>

        <span class="c">// Out of bounds</span>
<span class="c"></span>        <span class="k">if</span><span class="o">(</span><span class="nx">nNewItemIndex</span> <span class="o">&lt;</span> <span class="o">-</span><span class="m">2</span> <span class="o">||</span> <span class="nx">nNewItemIndex</span> <span class="o">&gt;=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_nDisplayedItems</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">return</span><span class="o">;</span>
        <span class="o">}</span>

        <span class="k">if</span><span class="o">(</span><span class="nx">oCurItem</span><span class="o">)</span> <span class="o">{</span>
            <span class="c">// Unhighlight current item</span>
<span class="c"></span>            <span class="k">this</span><span class="o">.</span><span class="nx">_toggleHighlight</span><span class="o">(</span><span class="nx">oCurItem</span><span class="o">,</span> <span class="s2">&quot;from&quot;</span><span class="o">);</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">itemArrowFromEvent</span><span class="o">.</span><span class="nx">fire</span><span class="o">(</span><span class="k">this</span><span class="o">,</span> <span class="nx">oCurItem</span><span class="o">);</span>
        <span class="o">}</span>
        <span class="k">if</span><span class="o">(</span><span class="nx">nNewItemIndex</span> <span class="o">==</span> <span class="o">-</span><span class="m">1</span><span class="o">)</span> <span class="o">{</span>
           <span class="c">// Go back to query (remove type-ahead string)</span>
<span class="c"></span>            <span class="k">if</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">delimChar</span> <span class="o">&amp;&amp;</span> <span class="k">this</span><span class="o">.</span><span class="nx">_sSavedQuery</span><span class="o">)</span> <span class="o">{</span>
                <span class="k">if</span><span class="o">(!</span><span class="k">this</span><span class="o">.</span><span class="nx">_textMatchesOption</span><span class="o">())</span> <span class="o">{</span>
                    <span class="k">this</span><span class="o">.</span><span class="nx">_oTextbox</span><span class="o">.</span><span class="nx">value</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_sSavedQuery</span><span class="o">;</span>
                <span class="o">}</span>
                <span class="k">else</span> <span class="o">{</span>
                    <span class="k">this</span><span class="o">.</span><span class="nx">_oTextbox</span><span class="o">.</span><span class="nx">value</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_sSavedQuery</span> <span class="o">+</span> <span class="k">this</span><span class="o">.</span><span class="nx">_sCurQuery</span><span class="o">;</span>
                <span class="o">}</span>
            <span class="o">}</span>
            <span class="k">else</span> <span class="o">{</span>
                <span class="k">this</span><span class="o">.</span><span class="nx">_oTextbox</span><span class="o">.</span><span class="nx">value</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_sCurQuery</span><span class="o">;</span>
            <span class="o">}</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">_oCurItem</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>
            <span class="k">return</span><span class="o">;</span>
        <span class="o">}</span>
        <span class="k">if</span><span class="o">(</span><span class="nx">nNewItemIndex</span> <span class="o">==</span> <span class="o">-</span><span class="m">2</span><span class="o">)</span> <span class="o">{</span>
            <span class="c">// Close container</span>
<span class="c"></span>            <span class="k">this</span><span class="o">.</span><span class="nx">_toggleContainer</span><span class="o">(</span><span class="kc">false</span><span class="o">);</span>
            <span class="k">return</span><span class="o">;</span>
        <span class="o">}</span>

        <span class="k">var</span> <span class="nx">oNewItem</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_aListItems</span><span class="o">[</span><span class="nx">nNewItemIndex</span><span class="o">];</span>

        <span class="c">// Scroll the container if necessary</span>
<span class="c"></span>        <span class="k">var</span> <span class="nx">oContent</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">;</span>
        <span class="k">var</span> <span class="nx">scrollOn</span> <span class="o">=</span> <span class="o">((</span><span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">Dom</span><span class="o">.</span><span class="nx">getStyle</span><span class="o">(</span><span class="nx">oContent</span><span class="o">,</span><span class="s2">&quot;overflow&quot;</span><span class="o">)</span> <span class="o">==</span> <span class="s2">&quot;auto&quot;</span><span class="o">)</span> <span class="o">||</span>
            <span class="o">(</span><span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">Dom</span><span class="o">.</span><span class="nx">getStyle</span><span class="o">(</span><span class="nx">oContent</span><span class="o">,</span><span class="s2">&quot;overflowY&quot;</span><span class="o">)</span> <span class="o">==</span> <span class="s2">&quot;auto&quot;</span><span class="o">));</span>
        <span class="k">if</span><span class="o">(</span><span class="nx">scrollOn</span> <span class="o">&amp;&amp;</span> <span class="o">(</span><span class="nx">nNewItemIndex</span> <span class="o">&gt;</span> <span class="o">-</span><span class="m">1</span><span class="o">)</span> <span class="o">&amp;&amp;</span>
        <span class="o">(</span><span class="nx">nNewItemIndex</span> <span class="o">&lt;</span> <span class="k">this</span><span class="o">.</span><span class="nx">_nDisplayedItems</span><span class="o">))</span> <span class="o">{</span>
            <span class="c">// User is keying down</span>
<span class="c"></span>            <span class="k">if</span><span class="o">(</span><span class="nx">nKeyCode</span> <span class="o">==</span> <span class="m">40</span><span class="o">)</span> <span class="o">{</span>
                <span class="c">// Bottom of selected item is below scroll area...</span>
<span class="c"></span>                <span class="k">if</span><span class="o">((</span><span class="nx">oNewItem</span><span class="o">.</span><span class="nx">offsetTop</span><span class="o">+</span><span class="nx">oNewItem</span><span class="o">.</span><span class="nx">offsetHeight</span><span class="o">)</span> <span class="o">&gt;</span> <span class="o">(</span><span class="nx">oContent</span><span class="o">.</span><span class="nx">scrollTop</span> <span class="o">+</span> <span class="nx">oContent</span><span class="o">.</span><span class="nx">offsetHeight</span><span class="o">))</span> <span class="o">{</span>
                    <span class="c">// Set bottom of scroll area to bottom of selected item</span>
<span class="c"></span>                    <span class="nx">oContent</span><span class="o">.</span><span class="nx">scrollTop</span> <span class="o">=</span> <span class="o">(</span><span class="nx">oNewItem</span><span class="o">.</span><span class="nx">offsetTop</span><span class="o">+</span><span class="nx">oNewItem</span><span class="o">.</span><span class="nx">offsetHeight</span><span class="o">)</span> <span class="o">-</span> <span class="nx">oContent</span><span class="o">.</span><span class="nx">offsetHeight</span><span class="o">;</span>
                <span class="o">}</span>
                <span class="c">// Bottom of selected item is above scroll area...</span>
<span class="c"></span>                <span class="k">else</span> <span class="k">if</span><span class="o">((</span><span class="nx">oNewItem</span><span class="o">.</span><span class="nx">offsetTop</span><span class="o">+</span><span class="nx">oNewItem</span><span class="o">.</span><span class="nx">offsetHeight</span><span class="o">)</span> <span class="o">&lt;</span> <span class="nx">oContent</span><span class="o">.</span><span class="nx">scrollTop</span><span class="o">)</span> <span class="o">{</span>
                    <span class="c">// Set top of selected item to top of scroll area</span>
<span class="c"></span>                    <span class="nx">oContent</span><span class="o">.</span><span class="nx">scrollTop</span> <span class="o">=</span> <span class="nx">oNewItem</span><span class="o">.</span><span class="nx">offsetTop</span><span class="o">;</span>

                <span class="o">}</span>
            <span class="o">}</span>
            <span class="c">// User is keying up</span>
<span class="c"></span>            <span class="k">else</span> <span class="o">{</span>
                <span class="c">// Top of selected item is above scroll area</span>
<span class="c"></span>                <span class="k">if</span><span class="o">(</span><span class="nx">oNewItem</span><span class="o">.</span><span class="nx">offsetTop</span> <span class="o">&lt;</span> <span class="nx">oContent</span><span class="o">.</span><span class="nx">scrollTop</span><span class="o">)</span> <span class="o">{</span>
                    <span class="c">// Set top of scroll area to top of selected item</span>
<span class="c"></span>                    <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">.</span><span class="nx">scrollTop</span> <span class="o">=</span> <span class="nx">oNewItem</span><span class="o">.</span><span class="nx">offsetTop</span><span class="o">;</span>
                <span class="o">}</span>
                <span class="c">// Top of selected item is below scroll area</span>
<span class="c"></span>                <span class="k">else</span> <span class="k">if</span><span class="o">(</span><span class="nx">oNewItem</span><span class="o">.</span><span class="nx">offsetTop</span> <span class="o">&gt;</span> <span class="o">(</span><span class="nx">oContent</span><span class="o">.</span><span class="nx">scrollTop</span> <span class="o">+</span> <span class="nx">oContent</span><span class="o">.</span><span class="nx">offsetHeight</span><span class="o">))</span> <span class="o">{</span>
                    <span class="c">// Set bottom of selected item to bottom of scroll area</span>
<span class="c"></span>                    <span class="k">this</span><span class="o">.</span><span class="nx">_oContainer</span><span class="o">.</span><span class="nx">_oContent</span><span class="o">.</span><span class="nx">scrollTop</span> <span class="o">=</span> <span class="o">(</span><span class="nx">oNewItem</span><span class="o">.</span><span class="nx">offsetTop</span><span class="o">+</span><span class="nx">oNewItem</span><span class="o">.</span><span class="nx">offsetHeight</span><span class="o">)</span> <span class="o">-</span> <span class="nx">oContent</span><span class="o">.</span><span class="nx">offsetHeight</span><span class="o">;</span>
                <span class="o">}</span>
            <span class="o">}</span>
        <span class="o">}</span>

        <span class="k">this</span><span class="o">.</span><span class="nx">_toggleHighlight</span><span class="o">(</span><span class="nx">oNewItem</span><span class="o">,</span> <span class="s2">&quot;to&quot;</span><span class="o">);</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">itemArrowToEvent</span><span class="o">.</span><span class="nx">fire</span><span class="o">(</span><span class="k">this</span><span class="o">,</span> <span class="nx">oNewItem</span><span class="o">);</span>
        <span class="k">if</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">typeAhead</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">_updateValue</span><span class="o">(</span><span class="nx">oNewItem</span><span class="o">);</span>
        <span class="o">}</span>
    <span class="o">}</span>
<span class="o">};</span>

<span class="c">/////////////////////////////////////////////////////////////////////////////</span>
<span class="c">//</span>
<span class="c">// Private event handlers</span>
<span class="c">//</span>
<span class="c">/////////////////////////////////////////////////////////////////////////////</span>
<span class="c"></span>
<span class="c">/**</span>
<span class="c"> * Handles &amp;lt;li&amp;gt; element mouseover events in the container.</span>
<span class="c"> *</span>
<span class="c"> * @method _onItemMouseover</span>
<span class="c"> * @param v {HTMLEvent} The mouseover event.</span>
<span class="c"> * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_onItemMouseover</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">v</span><span class="o">,</span><span class="nx">oSelf</span><span class="o">)</span> <span class="o">{</span>
    <span class="k">if</span><span class="o">(</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">prehighlightClassName</span><span class="o">)</span> <span class="o">{</span>
        <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_togglePrehighlight</span><span class="o">(</span><span class="k">this</span><span class="o">,</span><span class="s2">&quot;mouseover&quot;</span><span class="o">);</span>
    <span class="o">}</span>
    <span class="k">else</span> <span class="o">{</span>
        <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_toggleHighlight</span><span class="o">(</span><span class="k">this</span><span class="o">,</span><span class="s2">&quot;to&quot;</span><span class="o">);</span>
    <span class="o">}</span>

    <span class="nx">oSelf</span><span class="o">.</span><span class="nx">itemMouseOverEvent</span><span class="o">.</span><span class="nx">fire</span><span class="o">(</span><span class="nx">oSelf</span><span class="o">,</span> <span class="k">this</span><span class="o">);</span>
<span class="o">};</span>

<span class="c">/**</span>
<span class="c"> * Handles &amp;lt;li&amp;gt; element mouseout events in the container.</span>
<span class="c"> *</span>
<span class="c"> * @method _onItemMouseout</span>
<span class="c"> * @param v {HTMLEvent} The mouseout event.</span>
<span class="c"> * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_onItemMouseout</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">v</span><span class="o">,</span><span class="nx">oSelf</span><span class="o">)</span> <span class="o">{</span>
    <span class="k">if</span><span class="o">(</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">prehighlightClassName</span><span class="o">)</span> <span class="o">{</span>
        <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_togglePrehighlight</span><span class="o">(</span><span class="k">this</span><span class="o">,</span><span class="s2">&quot;mouseout&quot;</span><span class="o">);</span>
    <span class="o">}</span>
    <span class="k">else</span> <span class="o">{</span>
        <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_toggleHighlight</span><span class="o">(</span><span class="k">this</span><span class="o">,</span><span class="s2">&quot;from&quot;</span><span class="o">);</span>
    <span class="o">}</span>

    <span class="nx">oSelf</span><span class="o">.</span><span class="nx">itemMouseOutEvent</span><span class="o">.</span><span class="nx">fire</span><span class="o">(</span><span class="nx">oSelf</span><span class="o">,</span> <span class="k">this</span><span class="o">);</span>
<span class="o">};</span>

<span class="c">/**</span>
<span class="c"> * Handles &amp;lt;li&amp;gt; element click events in the container.</span>
<span class="c"> *</span>
<span class="c"> * @method _onItemMouseclick</span>
<span class="c"> * @param v {HTMLEvent} The click event.</span>
<span class="c"> * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_onItemMouseclick</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">v</span><span class="o">,</span><span class="nx">oSelf</span><span class="o">)</span> <span class="o">{</span>
    <span class="c">// In case item has not been moused over</span>
<span class="c"></span>    <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_toggleHighlight</span><span class="o">(</span><span class="k">this</span><span class="o">,</span><span class="s2">&quot;to&quot;</span><span class="o">);</span>
    <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_selectItem</span><span class="o">(</span><span class="k">this</span><span class="o">);</span>
<span class="o">};</span>

<span class="c">/**</span>
<span class="c"> * Handles container mouseover events.</span>
<span class="c"> *</span>
<span class="c"> * @method _onContainerMouseover</span>
<span class="c"> * @param v {HTMLEvent} The mouseover event.</span>
<span class="c"> * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_onContainerMouseover</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">v</span><span class="o">,</span><span class="nx">oSelf</span><span class="o">)</span> <span class="o">{</span>
    <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_bOverContainer</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>
<span class="o">};</span>

<span class="c">/**</span>
<span class="c"> * Handles container mouseout events.</span>
<span class="c"> *</span>
<span class="c"> * @method _onContainerMouseout</span>
<span class="c"> * @param v {HTMLEvent} The mouseout event.</span>
<span class="c"> * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_onContainerMouseout</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">v</span><span class="o">,</span><span class="nx">oSelf</span><span class="o">)</span> <span class="o">{</span>
    <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_bOverContainer</span> <span class="o">=</span> <span class="kc">false</span><span class="o">;</span>
    <span class="c">// If container is still active</span>
<span class="c"></span>    <span class="k">if</span><span class="o">(</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_oCurItem</span><span class="o">)</span> <span class="o">{</span>
        <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_toggleHighlight</span><span class="o">(</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_oCurItem</span><span class="o">,</span><span class="s2">&quot;to&quot;</span><span class="o">);</span>
    <span class="o">}</span>
<span class="o">};</span>

<span class="c">/**</span>
<span class="c"> * Handles container scroll events.</span>
<span class="c"> *</span>
<span class="c"> * @method _onContainerScroll</span>
<span class="c"> * @param v {HTMLEvent} The scroll event.</span>
<span class="c"> * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_onContainerScroll</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">v</span><span class="o">,</span><span class="nx">oSelf</span><span class="o">)</span> <span class="o">{</span>
    <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_oTextbox</span><span class="o">.</span><span class="nx">focus</span><span class="o">();</span>
<span class="o">};</span>

<span class="c">/**</span>
<span class="c"> * Handles container resize events.</span>
<span class="c"> *</span>
<span class="c"> * @method _onContainerResize</span>
<span class="c"> * @param v {HTMLEvent} The resize event.</span>
<span class="c"> * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_onContainerResize</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">v</span><span class="o">,</span><span class="nx">oSelf</span><span class="o">)</span> <span class="o">{</span>
    <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_toggleContainerHelpers</span><span class="o">(</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_bContainerOpen</span><span class="o">);</span>
<span class="o">};</span>


<span class="c">/**</span>
<span class="c"> * Handles textbox keydown events of functional keys, mainly for UI behavior.</span>
<span class="c"> *</span>
<span class="c"> * @method _onTextboxKeyDown</span>
<span class="c"> * @param v {HTMLEvent} The keydown event.</span>
<span class="c"> * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_onTextboxKeyDown</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">v</span><span class="o">,</span><span class="nx">oSelf</span><span class="o">)</span> <span class="o">{</span>
    <span class="k">var</span> <span class="nx">nKeyCode</span> <span class="o">=</span> <span class="nx">v</span><span class="o">.</span><span class="nx">keyCode</span><span class="o">;</span>

    <span class="nx">switch</span> <span class="o">(</span><span class="nx">nKeyCode</span><span class="o">)</span> <span class="o">{</span>
        <span class="nx">case</span> <span class="m">9</span><span class="o">:</span> <span class="c">// tab</span>
<span class="c"></span>            <span class="k">if</span><span class="o">(</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">delimChar</span> <span class="o">&amp;&amp;</span> <span class="o">(</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_nKeyCode</span> <span class="o">!=</span> <span class="nx">nKeyCode</span><span class="o">))</span> <span class="o">{</span>
                <span class="k">if</span><span class="o">(</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_bContainerOpen</span><span class="o">)</span> <span class="o">{</span>
                    <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">Event</span><span class="o">.</span><span class="nx">stopEvent</span><span class="o">(</span><span class="nx">v</span><span class="o">);</span>
                <span class="o">}</span>
            <span class="o">}</span>
            <span class="c">// select an item or clear out</span>
<span class="c"></span>            <span class="k">if</span><span class="o">(</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_oCurItem</span><span class="o">)</span> <span class="o">{</span>
                <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_selectItem</span><span class="o">(</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_oCurItem</span><span class="o">);</span>
            <span class="o">}</span>
            <span class="k">else</span> <span class="o">{</span>
                <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_toggleContainer</span><span class="o">(</span><span class="kc">false</span><span class="o">);</span>
            <span class="o">}</span>
            <span class="k">break</span><span class="o">;</span>
        <span class="nx">case</span> <span class="m">13</span><span class="o">:</span> <span class="c">// enter</span>
<span class="c"></span>            <span class="k">if</span><span class="o">(</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_nKeyCode</span> <span class="o">!=</span> <span class="nx">nKeyCode</span><span class="o">)</span> <span class="o">{</span>
                <span class="k">if</span><span class="o">(</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_bContainerOpen</span><span class="o">)</span> <span class="o">{</span>
                    <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">Event</span><span class="o">.</span><span class="nx">stopEvent</span><span class="o">(</span><span class="nx">v</span><span class="o">);</span>
                <span class="o">}</span>
            <span class="o">}</span>
            <span class="k">if</span><span class="o">(</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_oCurItem</span><span class="o">)</span> <span class="o">{</span>
                <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_selectItem</span><span class="o">(</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_oCurItem</span><span class="o">);</span>
            <span class="o">}</span>
            <span class="k">else</span> <span class="o">{</span>
                <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_toggleContainer</span><span class="o">(</span><span class="kc">false</span><span class="o">);</span>
            <span class="o">}</span>
            <span class="k">break</span><span class="o">;</span>
        <span class="nx">case</span> <span class="m">27</span><span class="o">:</span> <span class="c">// esc</span>
<span class="c"></span>            <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_toggleContainer</span><span class="o">(</span><span class="kc">false</span><span class="o">);</span>
            <span class="k">return</span><span class="o">;</span>
        <span class="nx">case</span> <span class="m">39</span><span class="o">:</span> <span class="c">// right</span>
<span class="c"></span>            <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_jumpSelection</span><span class="o">();</span>
            <span class="k">break</span><span class="o">;</span>
        <span class="nx">case</span> <span class="m">38</span><span class="o">:</span> <span class="c">// up</span>
<span class="c"></span>            <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">Event</span><span class="o">.</span><span class="nx">stopEvent</span><span class="o">(</span><span class="nx">v</span><span class="o">);</span>
            <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_moveSelection</span><span class="o">(</span><span class="nx">nKeyCode</span><span class="o">);</span>
            <span class="k">break</span><span class="o">;</span>
        <span class="nx">case</span> <span class="m">40</span><span class="o">:</span> <span class="c">// down</span>
<span class="c"></span>            <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">Event</span><span class="o">.</span><span class="nx">stopEvent</span><span class="o">(</span><span class="nx">v</span><span class="o">);</span>
            <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_moveSelection</span><span class="o">(</span><span class="nx">nKeyCode</span><span class="o">);</span>
            <span class="k">break</span><span class="o">;</span>
        <span class="nx">default</span><span class="o">:</span>
            <span class="k">break</span><span class="o">;</span>
    <span class="o">}</span>
<span class="o">};</span>

<span class="c">/**</span>
<span class="c"> * Handles textbox keypress events.</span>
<span class="c"> * @method _onTextboxKeyPress</span>
<span class="c"> * @param v {HTMLEvent} The keypress event.</span>
<span class="c"> * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_onTextboxKeyPress</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">v</span><span class="o">,</span><span class="nx">oSelf</span><span class="o">)</span> <span class="o">{</span>
    <span class="k">var</span> <span class="nx">nKeyCode</span> <span class="o">=</span> <span class="nx">v</span><span class="o">.</span><span class="nx">keyCode</span><span class="o">;</span>

        <span class="c">//Expose only to Mac browsers, where stopEvent is ineffective on keydown events (bug 790337)</span>
<span class="c"></span>        <span class="k">var</span> <span class="nx">isMac</span> <span class="o">=</span> <span class="o">(</span><span class="nx">navigator</span><span class="o">.</span><span class="nx">userAgent</span><span class="o">.</span><span class="nx">toLowerCase</span><span class="o">().</span><span class="nx">indexOf</span><span class="o">(</span><span class="s2">&quot;mac&quot;</span><span class="o">)</span> <span class="o">!=</span> <span class="o">-</span><span class="m">1</span><span class="o">);</span>
        <span class="k">if</span><span class="o">(</span><span class="nx">isMac</span><span class="o">)</span> <span class="o">{</span>
            <span class="nx">switch</span> <span class="o">(</span><span class="nx">nKeyCode</span><span class="o">)</span> <span class="o">{</span>
            <span class="nx">case</span> <span class="m">9</span><span class="o">:</span> <span class="c">// tab</span>
<span class="c"></span>                <span class="k">if</span><span class="o">(</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">delimChar</span> <span class="o">&amp;&amp;</span> <span class="o">(</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_nKeyCode</span> <span class="o">!=</span> <span class="nx">nKeyCode</span><span class="o">))</span> <span class="o">{</span>
                    <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">Event</span><span class="o">.</span><span class="nx">stopEvent</span><span class="o">(</span><span class="nx">v</span><span class="o">);</span>
                <span class="o">}</span>
                <span class="k">break</span><span class="o">;</span>
            <span class="nx">case</span> <span class="m">13</span><span class="o">:</span> <span class="c">// enter</span>
<span class="c"></span>                <span class="k">if</span><span class="o">(</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_nKeyCode</span> <span class="o">!=</span> <span class="nx">nKeyCode</span><span class="o">)</span> <span class="o">{</span>
                    <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">Event</span><span class="o">.</span><span class="nx">stopEvent</span><span class="o">(</span><span class="nx">v</span><span class="o">);</span>
                <span class="o">}</span>
                <span class="k">break</span><span class="o">;</span>
            <span class="nx">case</span> <span class="m">38</span><span class="o">:</span> <span class="c">// up</span>
<span class="c"></span>            <span class="nx">case</span> <span class="m">40</span><span class="o">:</span> <span class="c">// down</span>
<span class="c"></span>                <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">Event</span><span class="o">.</span><span class="nx">stopEvent</span><span class="o">(</span><span class="nx">v</span><span class="o">);</span>
                <span class="k">break</span><span class="o">;</span>
            <span class="nx">default</span><span class="o">:</span>
                <span class="k">break</span><span class="o">;</span>
            <span class="o">}</span>
        <span class="o">}</span>

        <span class="c">//TODO: (?) limit only to non-IE, non-Mac-FF for Korean IME support (bug 811948)</span>
<span class="c"></span>        <span class="c">// Korean IME detected</span>
<span class="c"></span>        <span class="k">else</span> <span class="k">if</span><span class="o">(</span><span class="nx">nKeyCode</span> <span class="o">==</span> <span class="m">229</span><span class="o">)</span> <span class="o">{</span>
            <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_queryInterval</span> <span class="o">=</span> <span class="nx">setInterval</span><span class="o">(</span><span class="k">function</span><span class="o">()</span> <span class="o">{</span> <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_onIMEDetected</span><span class="o">(</span><span class="nx">oSelf</span><span class="o">);</span> <span class="o">},</span><span class="m">500</span><span class="o">);</span>
        <span class="o">}</span>
<span class="o">};</span>

<span class="c">/**</span>
<span class="c"> * Handles textbox keyup events that trigger queries.</span>
<span class="c"> *</span>
<span class="c"> * @method _onTextboxKeyUp</span>
<span class="c"> * @param v {HTMLEvent} The keyup event.</span>
<span class="c"> * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_onTextboxKeyUp</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">v</span><span class="o">,</span><span class="nx">oSelf</span><span class="o">)</span> <span class="o">{</span>
    <span class="c">// Check to see if any of the public properties have been updated</span>
<span class="c"></span>    <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_initProps</span><span class="o">();</span>

    <span class="k">var</span> <span class="nx">nKeyCode</span> <span class="o">=</span> <span class="nx">v</span><span class="o">.</span><span class="nx">keyCode</span><span class="o">;</span>
    <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_nKeyCode</span> <span class="o">=</span> <span class="nx">nKeyCode</span><span class="o">;</span>
    <span class="k">var</span> <span class="nx">sText</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">value</span><span class="o">;</span> <span class="c">//string in textbox</span>
<span class="c"></span>
    <span class="c">// Filter out chars that don&#39;t trigger queries</span>
<span class="c"></span>    <span class="k">if</span><span class="o">(</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_isIgnoreKey</span><span class="o">(</span><span class="nx">nKeyCode</span><span class="o">)</span> <span class="o">||</span> <span class="o">(</span><span class="nx">sText</span><span class="o">.</span><span class="nx">toLowerCase</span><span class="o">()</span> <span class="o">==</span> <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_sCurQuery</span><span class="o">))</span> <span class="o">{</span>
        <span class="k">return</span><span class="o">;</span>
    <span class="o">}</span>
    <span class="k">else</span> <span class="o">{</span>
        <span class="nx">oSelf</span><span class="o">.</span><span class="nx">textboxKeyEvent</span><span class="o">.</span><span class="nx">fire</span><span class="o">(</span><span class="nx">oSelf</span><span class="o">,</span> <span class="nx">nKeyCode</span><span class="o">);</span>
    <span class="o">}</span>

    <span class="c">// Set timeout on the request</span>
<span class="c"></span>    <span class="k">if</span><span class="o">(</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">queryDelay</span> <span class="o">&gt;</span> <span class="m">0</span><span class="o">)</span> <span class="o">{</span>
        <span class="k">var</span> <span class="nx">nDelayID</span> <span class="o">=</span>
            <span class="nx">setTimeout</span><span class="o">(</span><span class="k">function</span><span class="o">(){</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_sendQuery</span><span class="o">(</span><span class="nx">sText</span><span class="o">);},(</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">queryDelay</span> <span class="o">*</span> <span class="m">1000</span><span class="o">));</span>

        <span class="k">if</span><span class="o">(</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_nDelayID</span> <span class="o">!=</span> <span class="o">-</span><span class="m">1</span><span class="o">)</span> <span class="o">{</span>
            <span class="nx">clearTimeout</span><span class="o">(</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_nDelayID</span><span class="o">);</span>
        <span class="o">}</span>

        <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_nDelayID</span> <span class="o">=</span> <span class="nx">nDelayID</span><span class="o">;</span>
    <span class="o">}</span>
    <span class="k">else</span> <span class="o">{</span>
        <span class="c">// No delay so send request immediately</span>
<span class="c"></span>        <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_sendQuery</span><span class="o">(</span><span class="nx">sText</span><span class="o">);</span>
    <span class="o">}</span>
<span class="o">};</span>

<span class="c">/**</span>
<span class="c"> * Handles text input box receiving focus.</span>
<span class="c"> *</span>
<span class="c"> * @method _onTextboxFocus</span>
<span class="c"> * @param v {HTMLEvent} The focus event.</span>
<span class="c"> * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_onTextboxFocus</span> <span class="o">=</span> <span class="k">function</span> <span class="o">(</span><span class="nx">v</span><span class="o">,</span><span class="nx">oSelf</span><span class="o">)</span> <span class="o">{</span>
    <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_oTextbox</span><span class="o">.</span><span class="nx">setAttribute</span><span class="o">(</span><span class="s2">&quot;autocomplete&quot;</span><span class="o">,</span><span class="s2">&quot;off&quot;</span><span class="o">);</span>
    <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_bFocused</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>
    <span class="k">if</span><span class="o">(!</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_bItemSelected</span><span class="o">)</span> <span class="o">{</span>
        <span class="nx">oSelf</span><span class="o">.</span><span class="nx">textboxFocusEvent</span><span class="o">.</span><span class="nx">fire</span><span class="o">(</span><span class="nx">oSelf</span><span class="o">);</span>
    <span class="o">}</span>
<span class="o">};</span>

<span class="c">/**</span>
<span class="c"> * Handles text input box losing focus.</span>
<span class="c"> *</span>
<span class="c"> * @method _onTextboxBlur</span>
<span class="c"> * @param v {HTMLEvent} The focus event.</span>
<span class="c"> * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_onTextboxBlur</span> <span class="o">=</span> <span class="k">function</span> <span class="o">(</span><span class="nx">v</span><span class="o">,</span><span class="nx">oSelf</span><span class="o">)</span> <span class="o">{</span>
    <span class="c">// Don&#39;t treat as a blur if it was a selection via mouse click</span>
<span class="c"></span>    <span class="k">if</span><span class="o">(!</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_bOverContainer</span> <span class="o">||</span> <span class="o">(</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_nKeyCode</span> <span class="o">==</span> <span class="m">9</span><span class="o">))</span> <span class="o">{</span>
        <span class="c">// Current query needs to be validated</span>
<span class="c"></span>        <span class="k">if</span><span class="o">(!</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_bItemSelected</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">if</span><span class="o">(!</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_bContainerOpen</span> <span class="o">||</span> <span class="o">(</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_bContainerOpen</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_textMatchesOption</span><span class="o">()))</span> <span class="o">{</span>
                <span class="k">if</span><span class="o">(</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">forceSelection</span><span class="o">)</span> <span class="o">{</span>
                    <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_clearSelection</span><span class="o">();</span>
                <span class="o">}</span>
                <span class="k">else</span> <span class="o">{</span>
                    <span class="nx">oSelf</span><span class="o">.</span><span class="nx">unmatchedItemSelectEvent</span><span class="o">.</span><span class="nx">fire</span><span class="o">(</span><span class="nx">oSelf</span><span class="o">,</span> <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_sCurQuery</span><span class="o">);</span>
                <span class="o">}</span>
            <span class="o">}</span>
        <span class="o">}</span>

        <span class="k">if</span><span class="o">(</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">_bContainerOpen</span><span class="o">)</span> <span class="o">{</span>
            <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_toggleContainer</span><span class="o">(</span><span class="kc">false</span><span class="o">);</span>
        <span class="o">}</span>
        <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_cancelIntervalDetection</span><span class="o">(</span><span class="nx">oSelf</span><span class="o">);</span>
        <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_bFocused</span> <span class="o">=</span> <span class="kc">false</span><span class="o">;</span>
        <span class="nx">oSelf</span><span class="o">.</span><span class="nx">textboxBlurEvent</span><span class="o">.</span><span class="nx">fire</span><span class="o">(</span><span class="nx">oSelf</span><span class="o">);</span>
    <span class="o">}</span>
<span class="o">};</span>

<span class="c">/**</span>
<span class="c"> * Handles form submission event.</span>
<span class="c"> *</span>
<span class="c"> * @method _onFormSubmit</span>
<span class="c"> * @param v {HTMLEvent} The submit event.</span>
<span class="c"> * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">AutoComplete</span><span class="o">.</span><span class="nx">prototype</span><span class="o">.</span><span class="nx">_onFormSubmit</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">v</span><span class="o">,</span><span class="nx">oSelf</span><span class="o">)</span> <span class="o">{</span>
    <span class="k">if</span><span class="o">(</span><span class="nx">oSelf</span><span class="o">.</span><span class="nx">allowBrowserAutocomplete</span><span class="o">)</span> <span class="o">{</span>
        <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_oTextbox</span><span class="o">.</span><span class="nx">setAttribute</span><span class="o">(</span><span class="s2">&quot;autocomplete&quot;</span><span class="o">,</span><span class="s2">&quot;on&quot;</span><span class="o">);</span>
    <span class="o">}</span>
    <span class="k">else</span> <span class="o">{</span>
        <span class="nx">oSelf</span><span class="o">.</span><span class="nx">_oTextbox</span><span class="o">.</span><span class="nx">setAttribute</span><span class="o">(</span><span class="s2">&quot;autocomplete&quot;</span><span class="o">,</span><span class="s2">&quot;off&quot;</span><span class="o">);</span>
    <span class="o">}</span>
<span class="o">};</span>
</pre></div>
                    </div>
			</div>
		</div>
		<div class="yui-b">
            <div class="nav">

                    <div class="module">
                        <h4>Modules</h4>
                        <ul class="content">

                                <li class=""><a href="module_animation.html">animation</a></li>

                                <li class="selected"><a href="module_autocomplete.html">autocomplete</a></li>

                                <li class=""><a href="module_button.html">button</a></li>

                                <li class=""><a href="module_calendar.html">calendar</a></li>

                                <li class=""><a href="module_connection.html">connection</a></li>

                                <li class=""><a href="module_container.html">container</a></li>

                                <li class=""><a href="module_datasource.html">datasource</a></li>

                                <li class=""><a href="module_datatable.html">datatable</a></li>

                                <li class=""><a href="module_dom.html">dom</a></li>

                                <li class=""><a href="module_dragdrop.html">dragdrop</a></li>

                                <li class=""><a href="module_element.html">element</a></li>

                                <li class=""><a href="module_event.html">event</a></li>

                                <li class=""><a href="module_history.html">history</a></li>

                                <li class=""><a href="module_logger.html">logger</a></li>

                                <li class=""><a href="module_menu.html">menu</a></li>

                                <li class=""><a href="module_slider.html">slider</a></li>

                                <li class=""><a href="module_tabview.html">tabview</a></li>

                                <li class=""><a href="module_treeview.html">treeview</a></li>

                                <li class=""><a href="module_yahoo.html">yahoo</a></li>
                        </ul>
                    </div>

                    <div class="module">
                        <h4>Classes</h4>
                        <ul class="content">
                                <li class=""><a href="YAHOO.widget.AutoComplete.html">YAHOO.widget.AutoComplete</a></li>
                                <li class=""><a href="YAHOO.widget.DataSource.html">YAHOO.widget.DataSource</a></li>
                                <li class=""><a href="YAHOO.widget.DS_JSArray.html">YAHOO.widget.DS_JSArray</a></li>
                                <li class=""><a href="YAHOO.widget.DS_JSFunction.html">YAHOO.widget.DS_JSFunction</a></li>
                                <li class=""><a href="YAHOO.widget.DS_XHR.html">YAHOO.widget.DS_XHR</a></li>
                        </ul>
                    </div>

                    <div class="module">
                        <h4>Files</h4>
                        <ul class="content">        
                                <li class="selected"><a href="AutoComplete.js.html">AutoComplete.js</a></li>
                                <li class=""><a href="DataSource.js.html">DataSource.js</a></li>
                        </ul>
                    </div>





            </div>
		</div>
	</div>
	<div id="ft">
        <hr />
        Copyright &copy; 2007 Yahoo! Inc. All rights reserved.
	</div>
</div>
</body>
</html>
